Question: Finish the following Bash script, insert-sort.sh. The script sorts a list of command line parameters in ascending order. For example, for the following command $
Finish the following Bash script, insert-sort.sh. The script sorts a list of command line parameters in ascending order.
For example, for the following command $ insert-sort.sh 7 2 3 9 -1
the script prints out -1 2 3 7 9
#!/bin/bash
arr=($@)
count=$#
for((i=1;i<$count;i=$i+1)); do
temp=${arr[$i]}
#find a location for the value in temp
for((j=$i;j>=1;_____________________)); do
if [ $temp -lt ${arr[$j-1]} ]
then
#move the elements that are larger than the value in temp
arr[j]=${arr[$j-1]} else _____________________
fi
done
#location for the value in temp is found. Now insert it. ________________________
done
echo ${arr[*]}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
