shellscript to sort numbers in ascending, descending order with the arguments supplied.
cat sort.sh
if [ $# -eq 0 ]
then
echo "Enter valid Argument "
exit
fi
for i in $*
do
echo $i >> tmpfile
done
echo "Your sorted data are below"
sort -nr tmpfile
echo "Script Ends"
output:
sh sort.sh 3 4 5 6 7
Your sorted data are below
7
6
5
4
3
Script Ends
Ascending order use sort -n
sh sort.sh 3 4 5 6 7
Your sorted data are below
3
4
5
6
7
Script Ends
cat sort.sh
if [ $# -eq 0 ]
then
echo "Enter valid Argument "
exit
fi
for i in $*
do
echo $i >> tmpfile
done
echo "Your sorted data are below"
sort -nr tmpfile
echo "Script Ends"
output:
sh sort.sh 3 4 5 6 7
Your sorted data are below
7
6
5
4
3
Script Ends
Ascending order use sort -n
sh sort.sh 3 4 5 6 7
Your sorted data are below
3
4
5
6
7
Script Ends