I'm trying to make a script that sort's numbers that are passed as parameters.( bubblesort)
#!/bin/sh
MINPARAMETERS=2
declare -a EXITNUMBERS
HELPNUMBER
if [ $# -lt $MINPARAMETERS ]
then
echo "The script needs at least " $MINPARAMETERS
echo
exit
else
echo "The value of the parameters before the sorting:"
echo $@
echo
fi
for (( h=1 ; h <= $# ; h++ ))
do
EXITNUMBERS=$@
done
for (( i=1 ; i <= $# ; i++ ))
do
for j
do
if [ $j -ge $((j+1)) ]
then
HELPNUMBER=${EXITNUMBERS[j]}
EXITNUMBERS[j]=${EXITNUMBERS[j+1]
EXITNUMBERS[j+1]=$HELPNUMBER
fi
done
done
echo "The value of the parameters after sorting"
echo ${EXITNUMBERS[*]}
The problem is that I can't find the right syntaxis for:
$[j+1] or $((j+1))
in the nested for-loop.
I'm working with ubuntu.
If you see any other mistakes or have tips, I would appreciate it.
Thanks