-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraypro1.sh
More file actions
45 lines (40 loc) · 861 Bytes
/
arraypro1.sh
File metadata and controls
45 lines (40 loc) · 861 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
39
40
41
42
43
44
45
#!/bin/bash -x
#generate random 3 digit
var1=10
count=1
while [ $count -le $var1 ]
do
number[$count]=${RANDOM:0:3}
((count++))
done
echo ${number[@]}
#for 2nd largest
l1=0
l2=0
for ((i=0; i<${#number[@]}; i++))
do
if [[ ${number[$i]} -gt $l1 ]]
then
l2=$l1;
l1=${number[$i]};
elif [[ ${number[$i]} -gt $l2 ]] && [[ ${number[$i]} -lt $l1 ]]
then
l2=${number[$i]};
fi
done
echo "2nd largest number is:" $l2
#for 2nd smallest
l3=1000
l4=1000
for ((i=0; i<${#number[@]}; i++))
do
if [[ ${number[$i]} -lt $l3 ]]
then
l4=$l3;
l3=${number[$i]};
elif [[ ${number[$i]} -lt $l4 ]] && [[ ${number[$i]} -gt $l3 ]]
then
l4=${number[$i]};
fi
done
echo "2nd smallest number is:" $l4