How to work with parameters in for-loop when making a script? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to work with parameters in for-loop when making a script?

I'm trying to make a script that sort's numbers that are passed as parameters.( bubblesort)


[code]
#!/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
[b]if [ $j -ge $((j+1)) ][/b]
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[*]}
[/code]


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
Sign In or Register to comment.