-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash.sh
More file actions
executable file
·79 lines (68 loc) · 1.38 KB
/
bash.sh
File metadata and controls
executable file
·79 lines (68 loc) · 1.38 KB
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
74
75
76
77
78
79
#!/bin/bash
checkCommandExist(){
command -v $1 >/dev/null 2>&1 || { echo "I require $1 but it's not installed. Aborting." >&2; exit 1; }
}
readBoolStr(){
if test $# == 1 ; then
echo $1 yes/no
read ANS
readBoolStr "$1" $ANS
ret=$?
return $ret
elif test $# == 2 ; then
case $2 in
yes|YES|Yes)
return 1
;;
no|NO|No)
return 0
;;
*)
readBoolStr "$1"
ret=$?
return $ret
;;
esac
else
readBoolStr "$1"
ret=$?
return $ret
fi
}
function contains() {
local n=$#
local value=${!n}
for ((i=1;i < $#;i++)) {
if [ "${!i}" == "${value}" ]; then
echo "y"
return 0
fi
}
echo "n"
return 1
}
function operationSelect(){
paramArray=()
echo "We support follow select:"
echo
while [ $# -gt 0 ]
do
paramArray+=("$1")
echo $1
shift
done
echo
echo
echo "Please select your env:"
read ANS
if [ $(contains "${paramArray[@]}" ${ANS}) == "y" ]; then
__=$ANS
else
operationSelect "${paramArray[@]}"
fi
}
function testOperationSelect(){
paramArray=(a "bb" "cc dd" "ee ff gg")
operationSelect "${paramArray[@]}"
echo your selection is: ${__}
}