-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.sh
executable file
·49 lines (42 loc) · 1.41 KB
/
demo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
source $(dirname $0)/opt-in.core.sh
source $(dirname $0)/opt-in.extension.sh
opt_init 'missing=<missing>' silent # debug
for arg
do
if opt_get "$arg" "hxci"; then
opt_match_cf - --stdin ||
opt_match_cf -h --help ||
opt_match_cf -x --extract ||
opt_match_cf -c --compress ||
opt_match_cf -i --index ||
opt_match_cf -v --verbose ||
opt_match_cv -f --file ||
opt_match_cv -O --output ||
opt_match_nonoptions
fi
done
opt_final
echo "incoming arg list:"; echo " $@"
$OPT_IN
echo "pre-processed arg list:"; echo " $@"
# Note: 'while [ -n "$1" ]' would not handle empty arguments correctly
echo "handled options (if any):"
while [ $# -gt 0 ]
do
case "$1" in
-h) echo " -h: help message" ;;
-x) echo " -x: extract" ;;
-c) echo " -c: compress" ;;
-i) echo " -i: index" ;;
-v) echo " -v: verbose" ;;
-f) echo " -f: filename=${2:-<empty>}"; shift ;;
-O) echo " -o: output=${2:-<empty>}"; shift ;;
--) echo " --: command separator, or file list continuation"; shift; break ;;
-) echo " -: stdin" ;;
?) echo " ?: invalid option $1, aborting."; exit 1 ;;
*) echo " unexpected, aborting: $1" ;;
esac
shift
done
echo "remaining non-options (if any):"; echo " $@"