-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript17.sh
More file actions
26 lines (23 loc) · 746 Bytes
/
script17.sh
File metadata and controls
26 lines (23 loc) · 746 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
#!/bin/bash
#Script to do calculations using case statment and if conditions
calc(){
read -p "Pl Give your Selection [ADD|SUB|MUL|DIV|EXIT]: " op
op=`echo $op |tr [a-z] [A-Z]`
case $op in
ADD)echo "Add=$(($a+$b))";;
SUB)echo "Sub=$(($a-$b))";;
MUL)echo "Mul=$(($a*$b))";;
DIV)echo "Div=$(($a/$b))";;
EXIT) echo "Thanks for using my script"
exit ;;
*)echo "Invalid operator selected, Try Again..." ;;
esac
calc
}
read -p "Pl Give 1st val: " a
read -p "Pl Give 2ns val: " b
if [ -z "$a" -o -z "$b" ];then
echo "Invalid Input, exiting"
exit 1
fi
calc