I looked everybody but I'm stuck with this code.
For example : The user calls ./array.sh 3 5 6 2 1 I am supposed to sort (i thought bubble sort) and print the array sorted.
#! /bin/bash
tab=( $@ )
define -i temp
for ((i = ${#tab[*]-1 ; i >= 0 ; i--)) ; do
for ((j = 0 ; i - 1; j++)) ; do
if [ ${tab[$i]} > ${tab[$i+1]} ] then
$temp = ${tab[$i+1]
${tab[$i+1]} = ${tab[$i]}
${$tab[$i]} = $temp
fi
done
echo ${tab[*]} #print the array
But bash is not happy with that, he keeps tellin me that I cannot assing values like that. What do I do wrong ? Can you help me please ? I looked in a lot of places but there is no way to find the solution.
Thanks you in advance guys.
printf "%s\n" "$@" | sort -nsuffices.