LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash scripting (https://www.linuxquestions.org/questions/linux-general-1/bash-scripting-698270/)

ZAMO 01-19-2009 02:21 AM

bash scripting
 
Hi all,


I need to know the meaning of a call in for loop?

Code:

for i in "$@" ; do
 echo $i
done

any idea? Got struck in an old script. What I want is, what is mean by
Code:

for i in "$@"
Thanks

eco 01-19-2009 02:25 AM

Quote:

@ Expands to the positional parameters, starting from one. When
the expansion occurs within double quotes, each parameter
expands to a separate word. That is, "$@" is equivalent to "$1"
"$2" ... If the double-quoted expansion occurs within a word,
the expansion of the first parameter is joined with the
beginning part of the original word, and the expansion of the
last parameter is joined with the last part of the original
word. When there are no positional parameters, "$@" and $@
expand to nothing (i.e., they are removed).
Streigh out of man bash ;)


... and to make things clearer:

Code:

#!/bin/bash

for i in "$@"; do
        echo $i
done

Code:

# . ./test.sh one two three
one
two
three



All times are GMT -5. The time now is 04:05 AM.