Working on this assignment.
Write a Bash script, insert-sort.sh, which sorts a list of command line parameters in ascending order. For example, your command will look something like: $ insert-sort.sh 7 2 3 9 -1 and type enter. Your program will return: -1 2 3 7 9
This is what I have so far
array=();
for param in "$@"; do
if [ -z "$array" ]; then
array[0]="$param";
else
array[param]="$param";
fi
done
echo ${array[@]}
The problem when I try to test the script, I get inconsistent answer. Sorted when it is not supposed to.
For example, if I run '/././BASH/insert-sort.sh' 1 3 2 I get 1 2 3
if I run '/././BASH/insert-sort.sh' 4 2 3 I get 4 2 3