#!/bin/bash
while getopts :d:m:y: FLAG; do case $FLAG in
d) # set day
DAY=$OPTARG
;;
m) # set month
MONTH=$OPTARG
;;
y) # set year
YEAR=$OPTARG
;;
\?) # unrecognized option - show help
echo "your help message here"
exit 0
;;
esac
done
# the rest of your program here handling your variables
echo "$DAY" "$MONTH "$YEAR"
如果你对短名称变量没问题,我看到的最简单的方法是这样使用
getopts
:例子