forked from Malavila/hcl-shell-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.sh
More file actions
40 lines (39 loc) · 976 Bytes
/
sort.sh
File metadata and controls
40 lines (39 loc) · 976 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
echo enter the no of element
read n1
for (( i=0; i<$n1; i++ ))
do
echo enter `expr $i + 1` the element.
read a[$i]
done
for (( i=0; i<$n1; i++ ))
do
for (( j=`expr $i + 1`; j<$n1; j++ ))
do
if [ ${a[$i]} -gt ${a[$j]} ]
then
x=${a[$i]}
a[$i]=${a[$j]}
a[$j]=$x
fi
done
done
echo 1.Ascending 2.Descending
echo enter your choice...
read c
if [ $c = 1 ]
then
echo the ascending order is....
for (( i=0; i<$n1; i++ ))
do
echo ${a[$i]}
done
elif [ $c = 2 ]
then
echo the descending order is...
for (( i=$n1; i>0; i-- ))
do
echo ${a[`expr $i - 1`]}
done
else
echo wrong choice......
fi