Skip to content

Instantly share code, notes, and snippets.

@echohn
Created Oct 8, 2015
Embed
What would you like to do?
bash getopts
while getopts "abc:def:ghi" OPT
do
echo "$OPT" $OPTIND $OPTARG # 这里$OPTIND 是一个索引序列号,$OPTARG 是选项里所记录的值,无值是为空,默认情况下选项是以空格分隔
case $OPT in
a) aflag=1
;;
b) bflag=1
;;
c) cflag=1
clist=$OPTARG
;;
f) fflag=1
flist=$OPTARG
;;
*) echo "Input ERROR"
exit 1
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment