Debian Codegraph @

ex33a.sh

raw symbols SCIP
1 #!/bin/bash
2 # Using getopt
3
4 # Try the following when invoking this script:
5 # sh ex33a.sh -a
6 # sh ex33a.sh -abc
7 # sh ex33a.sh -a -b -c
8 # sh ex33a.sh -d
9 # sh ex33a.sh -dXYZ
10 # sh ex33a.sh -d XYZ
11 # sh ex33a.sh -abcd
12 # sh ex33a.sh -abcdZ
13 # sh ex33a.sh -z
14 # sh ex33a.sh a
15 # Explain the results of each of the above.
16
17 E_OPTERR=65
18
19 if [ "$#" -eq 0 ]
20 then # Script needs at least one command-line argument.
21 echo "Usage $0 -[options a,b,c]"
22 exit $E_OPTERR
23 fi
24
25 set -- `getopt "abcd:" "$@"`
26 # Sets positional parameters to command-line arguments.
27 # What happens if you use "$*" instead of "$@"?
28
29 while [ ! -z "$1" ]
30 do
31 case "$1" in
32 -a) echo "Option \"a\"";;
33 -b) echo "Option \"b\"";;
34 -c) echo "Option \"c\"";;
35 -d) echo "Option \"d\" $2";;
36 *) break;;
37 esac
38
39 shift
40 done
41
42 # It is usually better to use the 'getopts' builtin in a script.
43 # See "ex33.sh."
44
45 exit 0