LINUX SEHLL program for Performing SORTING IN ASCENDING ORDER | Operating System (OS) LAB in LINUX| Print number in ascending order

AIM:
To write a shell program for printing the number in ascending order.
ALGORITHM:
· Get the numbers to be sorted.
· Check whether A is less than both B and c.
· if true print A is the first element in ascending order.
· if false print C followed by B and A.
· Repeat this for the three numbers until all are stored.
· Print ascending order.
· Terminate the program.

PROGRAM SOURCE CODE
echo ”enter 3 numbers”
read a
read b
read c
if [$a –eq $b –a $a –eq $c]
then
echo ”$a”
echo ”$b”
echo ”$c”
elif [$a –lt $b –a $a –lt $c]
then
echo ”the ascending order of 3 numbers”
echo ”$a”
if [$b –le $c]
then
echo ”$b”
echo “$c”
else
echo “$c”
echo “$b”
fi
elif [$b –lt $a – a$b -lt$c]
then
echo “the ascending order of the 3 numbers”
echo “$b”
if [$a –le$c]
then
echo ”$a”
echo “$c”
else
echo “$c”
echo”$a”
fi
else
echo “the ascending order of the 3 numbers”
echo “$c”
if [$a –le $b]
then
echo ”$a”
echo “$b”
else
echo “$b”
echo “$a”
fi
fi




CONCLUSION:
Thus the shell program for sorting the three numbers in ascending order is written and executed successfully.

Related post