Skip to content

Instantly share code, notes, and snippets.

@echohn
Created October 8, 2015 12:33
Show Gist options
  • Save echohn/c62a3d0a974e01ac22cd to your computer and use it in GitHub Desktop.
Save echohn/c62a3d0a974e01ac22cd to your computer and use it in GitHub Desktop.
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