Linux Support

Moderators: None (Apply to moderate this forum)
Number of threads: 332
Number of posts: 953

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to work with parameters in for-loop when making a script? Posted by gabbe987 on 20 Aug 2009 at 12:32 PM
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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.