Tag Archives: while

Shell script menu

This is an example of how to create a bash menu using while and read.

 bash | 
 
 copy code |
?

01
#!/bin/sh
02
echo "Use one of the following options"
03
echo " d : run date command"
04
echo "  : "
05
echo " q: quit this menu"
06
echo "enter your choice or type "q" to quit : \c"
07
read option
08
while [ "$option" != "q" ]
09
 do
10
 case $option in
11
 d ) date
12
 shift
13
 echo "enter your choice or type "q" to quit : \c"
14
 read option
15
 ;;
16
  ) 
17
 shift
18
 echo "enter your choice or type "q" to quit : \c"
19
 read option
20
 ;;
21
 
22
#                       ...
23
24
25
26
27
 shift
28
 echo "enter your choice or type "q" to quit : \c"
29
 read option
30
 ;;
31
 read option
32
 ;;
33
 q ) exit 0
34
 ;;
35
 esac