LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Bash: Iterate through $@ (easy++) (http://www.linuxquestions.org/questions/programming-9/bash-iterate-through-%24%40-easy-165609/)

beatnik007 04-03-2004 01:01 AM

Bash: Iterate through $@ (easy++)
 
Excuse me for being such a newbie but, well this is the place for it right?

I've been reading the bash manpage, but can't make sense of the definition of "list". As such I don't understand how to iterate through the input parameters. I've tried variations on the following:

Code:

for param in $@ do {
    echo $param;
}

But nothing seems to be syntactically correct.

As an aside, is there a good site for beginners bash?

Thanks

verstapp 04-03-2004 01:25 AM

Try

#!/bin/bash
# first let it know which shell you're using.

for param in $@
do
{
echo $param;
}
done

You need the 'done' to 'close off' the 'do'. Putting the 'do' on a different line from the 'if' means that you don't have to put a ';' after the '$@', there are lots of these little things to learn.
2: type "bash tutorial" into google, there are lots of them.

beatnik007 04-03-2004 01:39 AM

Thanks Peter, much appreciated.

Cheers
Jem


All times are GMT -5. The time now is 01:03 PM.