-
Notifications
You must be signed in to change notification settings - Fork 2
/
getops.sh
73 lines (73 loc) · 1.46 KB
/
getops.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
## getops
## version 0.0.3 - allow multiword shortops
##################################################
on-shortops-case() {
case ${1} in
t) {
option_test="true"
echo 1
} ;;
v) {
option_variable="${2}"
echo 2
} ;;
esac
}
#-------------------------------------------------
on-shortops() {
str_length() { { local str ; str=${@} ; }
echo ${str} | wc -c
}
#echo ${1} 1>&2
local i
for i in $( seq $(( $( str_length ${1:1} ) - 1 )) )
do
#echo ${1:${i}:1} 1>&2
${FUNCNAME}-case ${1:${i}:1} ${@:2}
done
}
#-------------------------------------------------
on-longops() {
#echo ${@} 1>&2
echo 1 # shift 1
}
#-------------------------------------------------
getops() {
while [ ${#} -gt 0 ]
do
case ${1} in
--) { # terminate all options
true # end of options
break
} ;;
-*-) {
false || {
error "malformed short option" "${FUNCNAME}" "${LINENO}"
false
}
} ;;
--*) {
on-longops $( echo ${@} | sed -e 's/--//' ) 1>/dev/null
shift $( on-longops $( echo ${@} | sed -e 's/--//' ) )
continue
} ;;
-*) {
on-shortops ${@} &>/dev/null
shift $( on-shortops ${@} )
continue
} ;;
*) { # not an option
true
} ;;
esac
#echo ${#}
shift
sleep 1
done
}
##################################################
## generated by create-stub2.sh v0.1.1
## on Mon, 11 Jun 2018 22:38:41 +0900
## see <https://github.com/temptemp3/sh2>
##################################################