-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest4.sh
74 lines (67 loc) · 1.76 KB
/
test4.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
74
#!/bin/bash
#title: menu.sh
#description: Menu which allows multiple items to be selected
#author: Nathan Davieau
# Based on script from MestreLion
#created: May 19 2016
#updated: N/A
#version: 1.0
#usage: ./menu.sh
#==============================================================================
#Menu options
options[0]="AAA"
options[1]="BBB"
options[2]="CCC"
options[3]="DDD"
options[4]="EEE"
#Actions to take based on selection
function ACTIONS {
if [[ ${choices[0]} ]]; then
#Option 1 selected
echo "Option 1 selected"
fi
if [[ ${choices[1]} ]]; then
#Option 2 selected
echo "Option 2 selected"
fi
if [[ ${choices[2]} ]]; then
#Option 3 selected
echo "Option 3 selected"
fi
if [[ ${choices[3]} ]]; then
#Option 4 selected
echo "Option 4 selected"
fi
if [[ ${choices[4]} ]]; then
#Option 5 selected
echo "Option 5 selected"
fi
}
#Variables
ERROR=" "
#Clear screen for menu
clear
#Menu function
function MENU {
echo "Menu Options"
for NUM in ${!options[@]}; do
echo "[""${choices[NUM]:- }""]" $(( NUM+1 ))") ${options[NUM]}"
done
echo "$ERROR"
}
#Menu loop
while MENU && read -e -p "Select the desired options using their number (again to uncheck, ENTER when done): " -n1 SELECTION && [[ -n "$SELECTION" ]]; do
clear
if [[ "$SELECTION" == *[[:digit:]]* && $SELECTION -ge 1 && $SELECTION -le ${#options[@]} ]]; then
(( SELECTION-- ))
if [[ "${choices[SELECTION]}" == "+" ]]; then
choices[SELECTION]=""
else
choices[SELECTION]="+"
fi
ERROR=" "
else
ERROR="Invalid option: $SELECTION"
fi
done
ACTIONS