Skip to main content
1 of 3
cuonglm
  • 158.3k
  • 41
  • 342
  • 421

Here is a simple script to demonstrates the different between $* and $@:

#!/bin/bash function test_param() { echo "Receive $# parameters"; echo Using '$*'; echo for param in $*; do echo "==>$param<=="; done; echo echo Using '"$*"'; for param in "$*"; do echo "==>$param<=="; done; echo echo Using '$@'; for param in $@; do echo "==>$param<=="; done; echo echo Using '"$@"'; for param in "$@"; do echo "==>$param<=="; done } IFS="^${IFS}" test_param 1 2 3 "a b c" 

Output:

% cuonglm at ~ % bash test.sh Receive 4 parameters Using $* ==>1<== ==>2<== ==>3<== ==>a<== ==>b<== ==>c<== Using "$*" ==>1^2^3^a b c<== Using $@ ==>1<== ==>2<== ==>3<== ==>a<== ==>b<== ==>c<== Using "$@" ==>1<== ==>2<== ==>3<== ==>a b c<== 

In array syntax, the no different when using $* or $@. It only make sense when you use with double quotes "$*" and "$@".

cuonglm
  • 158.3k
  • 41
  • 342
  • 421