-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_21_select_loop.sh
More file actions
42 lines (32 loc) · 982 Bytes
/
tutorial_21_select_loop.sh
File metadata and controls
42 lines (32 loc) · 982 Bytes
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
#! /bin/bash
#select loop: it's is kind of same as 'for loop'. It first iterate over given list of variables and print them on terminal as menu type structure with number associated with each of them(like ordered list) and ask the user to enter number from them( select any one variable ). After user enter the number, command in select loop will execute according to (or for) selected variable
# syntax:
# select varName in list
# do
# command1
# command2
# ...
# commandn
# done
#Note: to come out of the loop press ctrl + c
# select Name in Dhara Mahi Drishty Aditi Khushi
# do
# echo "$Name selected"
# done
# Select loop is often used with cases
#Example
select name in Dhara Mahi Drishty Khushi
do
case $name in
Dhara )
echo Dhara selected ;;
Mahi )
echo Mahi selected ;;
Drishty )
echo Drishty selected ;;
Khushi )
echo Khushi selected ;;
* )
echo "Please enter numbers from 1 to 4" ;;
esac
done