Difference between $@ and $* in bash scripting -


i'm new in bash , i'm learning it, , have doubt real difference between use of $@ , s*.

i red here bash special parameters

i understand both expand positional parameters, difference occurs within double quotes. way "$@" = "$1" "$2"..."$n" different "s*" = "$1$2...$n".

i try understand simple script:

if [ $# -gt 0 ];        echo "your command line contains $# arguments"  else        echo "your command line contains no arguments"        exit  fi  echo "params are: " echo $@   echo $*  echo "$@"     echo "$*" 

if execute script in terminal ~./my_script par1 par2 par3

the result same:

params are: par1 par2 par3 par1 par2 par3 par1 par2 par3 par1 par2 par3 

maybe don't understand real use of both special variables , if example correct or not. i'd figure out point example.

from http://tldp.org/ldp/abs/html/refcards.html:

"$*" positional parameters (as single word) *

"$@" positional parameters (as separate strings)

this code shows it: given string items separated spaces, $@ considers every word new item, while $* considers them same parameter.

echo "params for: \$@" item in "${@}"         echo $item -- done  echo "params : \$*" item in "${*}"         echo $item -- done 

test:

$ ./a par1 par2 par3 command line contains 3 arguments params for: $@ par1 -- par2 -- par3 -- params : $* par1 par2 par3 -- 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -