-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbashmenu.bash
More file actions
executable file
·68 lines (60 loc) · 1.45 KB
/
Copy pathbashmenu.bash
File metadata and controls
executable file
·68 lines (60 loc) · 1.45 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
#!/bin/bash
#h-------------------------------------------------------------------------------
#h
#h Name: bashmenu.bash
#h Type: Linux shell script
#h Purpose: select menu for bash scripts
#h Project:
#h Usage: <selected option>=`bashmenu.bash <title> <list of options>`
#h Result:
#h Examples:
#h Outline:
#h Resources: whiptail
#h Platforms: Linux
#h Authors: peb piet66
#h Version: V1.0 2023-06-24/peb
#v History: V1.0 2023-06-21/peb first version
#h Copyright: (C) piet66 2023
#h
#h-------------------------------------------------------------------------------
#b Constants
#-----------
MODULE='bashmenu.bash'
VERSION='V1.0'
WRITTEN='2023-06-24/peb'
if [ $# -lt 2 ]
then
echo "wrong number of parameters: $#" >&2
echo 0
exit 1
fi
title="$1"; shift
[ "$title" == "" ] && title="Menu"
#whiptail seems not to support blanks in options:
space=`printf '\xE2\x80\x89'`
shopt -s extglob #for replace all blanks in an option by space
num=0
list+="$num break "
for option in "$@"
do
num=$((num + 1))
list+="${num} ${option//+( )/$space} "
done
shopt -u extglob #reset
ret=`whiptail --nocancel --menu "$title" 0 0 0 $list 3>&1 1>&2 2>&3`
r=$?
[ $r -eq 255 ] && r=0
[ $r -eq 1 ] && r=0
if [ $r -ne 0 ]
then
echo $r:$ret >&2
echo ""
exit 1
fi
[ "$ret" == "" ] && ret=""
case "$ret" in
"") echo "";;
"0") echo "break";;
*) echo ${!ret};;
esac
exit 0