Programming Tutorials

Comment on Tutorial - Sort numbers using arrays in Shell Script By Vivek G



Comment Added by : shruthi

Comment Added at : 2013-01-18 06:00:08

Comment on Tutorial : Sort numbers using arrays in Shell Script By Vivek G
This will give the output check it out

nos=( 2 4 1 30 23 )
echo "Original Numbers in array:"
for ((i = 0; i <= 4 ; i++ ))
do

echo " ${nos[i]} "
done


for (( i = 0; i <= 4 ; i++ ))
do
for (( j = $i; j <= 4; j++ ))
do
if [ ${nos[i]} -gt ${nos[j]} ]; then
t=${nos[i]}
nos[i]=${nos[j]}
nos[j]=$t
fi
done
done

echo -e "\nSorted Numbers in Ascending Order:"
for (( i=0; i <= 4; i++ ))
do
echo "${nos[i]}"
done


View Tutorial