Created
October 8, 2015 12:33
-
-
Save echohn/c62a3d0a974e01ac22cd to your computer and use it in GitHub Desktop.
bash getopts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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