source: trunk/essentials/app-shells/bash/tests/getopts7.sub

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 538 bytes
Line 
1aflag=
2bflag=
3
4while getopts :ab: opt-var "$@"
5do
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
18done
19
20if [ ! -z "$aflag" ] ; then echo -a specified ; fi
21if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi
22
23if [ "$OPTIND" -gt 1 ]
24then
25 shift $(( $OPTIND - 1 ))
26fi
27
28echo remaining args: "$*"
29
30exit 0
Note: See TracBrowser for help on using the repository browser.