I'm just learning bash scripting. Tried to sort the array, it says "integer expression expected for lines 10 and 15. What am I doing wrong? Here is my script:
#!/bin/bash
array=('5' '9' '0' '20' '2' '15' '6' '25' '1')
b=0
n=${#array[@]}
i=0
while [ "$i" -lt "$n" ]
do
c=${array[$i]}
d=${array[$i+1]}
if [ "$c" -lt "$d" ]; then
j=0
while [ "$j" -le "$i" ]
do
f=${b[$j]}
if [ "$f" -gt "$c" ];
then b[$j]=$c
echo "${b[$j]}"
fi
j=$(( j+1 ))
done
fi
i=$(( i+1 ))
done
$bfirst as a scalar (b=0) and then later as an array (${b[$j]}).bash -x ./the-scriptshould make it apparent what the problem is. Again, look at your usage the$bvariable.