-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-input.sh
93 lines (75 loc) · 1.24 KB
/
user-input.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
first(){
if [[ $1 == "Bharadwaj" && $2 == "bd" ]]
then
echo "Login successful"
else
echo "Login failed"
fi
}
oddeven(){
# num=$1
# echo "$1"
if (( $1 % 2 == 0 ))
then
echo "The number is EVEN"
else
echo "The number is ODD"
fi
}
prime(){
if (( $1 == 0 ))
then
echo "Neither prime nor composite"
elif (( $1 == 1 ))
then
echo "Not a prime number"
else
if (( $1==0 ))
then
echo "Neither prime nor composite"
elif (($1==1))
then
echo "Not a prime number"
else
declare -i x=$(( $1/2 ))
declare -i f=0
for((i=2; i<=$x; i++ ))
do
if (($1%i==0))
then
echo "Its not a Prime number"
(( f=1 ))
break
fi
done
if (( $f == 0 ))
then
echo "Its a Prime number"
fi
fi
fi
}
roll(){
num=$(( 1 + $RANDOM % 6 ))
echo "The number you got is : $num"
}
square(){
echo "The square of the number is : $(( $1 * $1 ))"
}
user(){
#echo "Choose one of the following functionality"
#select option in "Roll a dice" "Odd or Even number" "Prime number" "Quit"
#do
case $1 in
ROLL) roll;;
ODDEVEN) oddeven $2;;
PRIME) prime $2;;
SQUARE) square $2;;
QUIT) ;;
*) echo "Wrong option. Choose another one.";;
esac
#done
}
#first $1 $2
user $1 $2