Debian Codegraph @

UseGetOpt-2.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 # UseGetOpt-2.sh
4 # Modified version of the script for illustrating tab-expansion
5 #+ of command-line options.
6 # See the "Introduction to Tab Expansion" appendix.
7
8 # Possible options: -a -d -f -l -t -h
9 #+ --aoption, --debug --file --log --test -- help --
10
11 # Author of original script: Peggy Russell <[email protected]>
12
13
14 # UseGetOpt () {
15 declare inputOptions
16 declare -r E_OPTERR=85
17 declare -r ScriptName=${0##*/}
18 declare -r ShortOpts="adf:hlt"
19 declare -r LongOpts="aoption,debug,file:,help,log,test"
20
21 DoSomethingscip-shell shell abs-guide 10-4 DoSomething(). () {
22 echoscip-shell system . . echo. "The function name is '${FUNCNAME}'"
23 }
24
25 inputOptions=$(getoptscip-shell system . . getopt. -o "${ShortOpts}" --long \
26 "${LongOpts}" --name "${ScriptName}" -- "${@}")
27
28 if [[ ($? -ne 0) || ($# -eq 0) ]]; then
29 echoscip-shell system . . echo. "Usage: ${ScriptName} [-dhlt] {OPTION...}"
30 exit $E_OPTERR
31 fi
32
33 eval set -- "${inputOptions}"
34
35
36 while truescip-shell system . . true.; do
37 case "${1}" in
38 --aoption | -a) # Argument found.
39 echoscip-shell system . . echo. "Option [$1]"
40 ;;
41
42 --debug | -d) # Enable informational messages.
43 echoscip-shell system . . echo. "Option [$1] Debugging enabled"
44 ;;
45
46 --file | -f) # Check for optional argument.
47 case "$2" in #+ Double colon is optional argument.
48 "") # Not there.
49 echoscip-shell system . . echo. "Option [$1] Use default"
50 shift
51 ;;
52
53 *) # Got it
54 echoscip-shell system . . echo. "Option [$1] Using input [$2]"
55 shift
56 ;;
57
58 esac
59 DoSomethingscip-shell shell abs-guide 10-4 DoSomething().
60 ;;
61
62 --log | -l) # Enable Logging.
63 echoscip-shell system . . echo. "Option [$1] Logging enabled"
64 ;;
65
66 --test | -t) # Enable testing.
67 echoscip-shell system . . echo. "Option [$1] Testing enabled"
68 ;;
69
70 --help | -h)
71 echoscip-shell system . . echo. "Option [$1] Display help"
72 break
73 ;;
74
75 --) # Done! $# is argument number for "--", $@ is "--"
76 echoscip-shell system . . echo. "Option [$1] Dash Dash"
77 break
78 ;;
79
80 *)
81 echoscip-shell system . . echo. "Major internal error!"
82 exit 8
83 ;;
84
85 esac
86 echoscip-shell system . . echo. "Number of arguments: [$#]"
87 shift
88 done
89
90 shift
91
92 # }
93
94 exit