Memoize |
BasicWerk
EC Support
Technique
Facebook
|
20141108093206_zsh_getopts |
|
zsh_getopts
sample_getopts.zsh
#! /bin/zsh
aflag=FALSE
bflag=FALSE
value=
file=
OPT=
while getopts abv:f: OPT
do
case $OPT in
a) aflag=TRUE
;;
b) bflag=TRUE
;;
v) value=$OPTARG
;;
f) file=$OPTARG
;;
\?) echo "Usage: $0 [-ab] [-v value] [-f filename] ..." 1>&2
exit 1
;;
esac
done
shift `expr $OPTIND - 1`
echo "a) $aflag b) $bflag v) $value f) $file \$1) $1 rest) $*"
実行例 % sample_getopts.zsh a) FALSE b) FALSE v) f) $1) rest) % sample_getopts.zsh -ab a) TRUE b) TRUE v) f) $1) rest) % sample_getopts.zsh -v VALUE a) FALSE b) FALSE v) VALUE f) $1) rest) % sample_getopts.zsh -f somefile a) FALSE b) FALSE v) f) somefile $1) rest) % sample_getopts.zsh -v VALUE otherfile1 a) FALSE b) FALSE v) VALUE f) $1) otherfile1 rest) otherfile1 % sample_getopts.zsh -v VALUE otherfile1 otherfile2 a) FALSE b) FALSE v) VALUE f) $1) otherfile1 rest) otherfile1 otherfile2
|
| © Shin Nakamura/BasicWerk 2014 |