Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.