]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/getopts7.sub
Bash-4.3 patch 7
[thirdparty/bash.git] / tests / getopts7.sub
1 aflag=
2 bflag=
3
4 while getopts :ab: opt-var "$@"
5 do
6 case $name in
7 a) aflag=1 ;;
8 b) bflag=1
9 bval=$OPTARG;;
10 :) echo $0: error: option \`$OPTARG\' requires an argument
11 echo Usage: $0 [-a] [-b value] args
12 exit 2;;
13 ?) echo $0: error: illegal option character \`$OPTARG\'
14 echo Usage: $0 [-a] [-b value] args
15 exit 2;;
16 esac
17
18 done
19
20 if [ ! -z "$aflag" ] ; then echo -a specified ; fi
21 if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi
22
23 if [ "$OPTIND" -gt 1 ]
24 then
25 shift $(( $OPTIND - 1 ))
26 fi
27
28 echo remaining args: "$*"
29
30 exit 0