-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.sh
More file actions
52 lines (45 loc) · 1 KB
/
1.sh
File metadata and controls
52 lines (45 loc) · 1 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
#!/bin/bash
# creating a menu with the following options
echo "1. Find Odd or even number"
echo "2. Find smallest among three numbers"
echo -n "Enter your menu choice [1-4]: "
# Running a forever loop using while statement
# This loop will run untill select the exit option.
# User will be asked to select option again and again
while :
do
# reading choice
read choice
# case statement is used to compare one value with the multiple cases.
case $choice in
# Pattern 1
1)echo -n "Enter a number:"
read n
if [ `expr $n % 2` == 0 ]
then
echo "$n is even"
else
echo "$n is Odd"
fi;;
# Pattern 2
2)echo "enter num_1: "
read num1
echo "enter num_2: "
read num2
echo "enter num_3 : "
read num3
s=$num1
if [ $num2 -lt $s ]
then
s=$num2
fi
if [ $num3 -lt $s ]
then
s=$num3
fi
echo Smallest of $num1 $num2 $num3 is $s;;
# Default Pattern
*) echo "invalid option";;
esac
echo -n "Enter your menu choice [1 or 2]: "
done