vim cash.sh:
while getopts ":s:e:" opt
do
case $opt in
"s")
start_month=$OPTARG
;;
"e")
end_month=$OPTARG
;;
":")
info="no value for expected option "
\?)
info="unexpected option"
*)
info="default"
;;
esac
done
echo "start_month:$start_month"
echo "end_month:$end_month"
echo "info:$info"
调用刚才写好的cash.sh,调用3次,分别查看其输出结果,如下:
1)./case.sh -s 2222-06 -e 3333-09
satrt_month:2222-06
end_moth:3333-09
info:
2)./case.sh -s 2222-06 -e
satrt_month:2222-06
end_moth:
info:no value for expected option
3)./case.sh -s 2222-06 -f
satrt_month:2222-06
end_moth:
info:unexpected optin