-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.sh
executable file
·45 lines (45 loc) · 1.09 KB
/
example.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
#!/usr/bin/env sh
make || exit
spec='flags: f,flag=-g=-h g=-h=-qwerty qwerty=-flag=-h=-g h,help; parameters: q,asdf u=defval nothing zzz,z,Z=someth; positionals: asdf test;'
helpmsg='
help = print this help message
flag = a random flag
g = i dunno, its nonsense
qwerty = a keyboard layout
asdf = q param
u = something
zzz = a bunch of zs
'
#tr '\0' '\n' < /proc/$$/cmdline | head -n2
#cat /proc/$$/comm
#cat -v /proc/$$/cmdline
#echo
#wc /proc/$$/cmdline
# print out the raw output
echo raw output:
vars="$(echo "$spec" | ./clparser --no-output-empty -e --help-msg "$helpmsg" -- "$@")"
ec=$?
printf '%s\n' "$vars"
if [ "$ec" -ne 0 ]; then
echo exit code: $ec
exit $ec
fi
# actually run it and show results
echo variable results:
eval "$vars"
echo f,flag = "$flag"
echo g = "$g"
echo qwerty = "$qwerty"
echo h,help = "$help"
echo q,asdf = "$asdf"
echo u = "$u"
echo nothing = "$nothing"
echo zzz,z,Z = "$Z"
echo positional params:
echo asdf = "$asdf"
echo test = "$test"
#printf 'default vals: %s\n' "$*"
#printf 'default vals: %s\n' "$args"
printf 'positional args:'
printf " '%s'" "$@"
printf '\n'