Explain the difference between `"$@"`, `"$*"`, `$@` and `$*`.
IntermediateConceptVariables, quoting and expansions
Answer
show() { printf '[%s]\n' "$@"; }
set -- "a b" c
show "$@" # [a b] [c] each argument preserved
show "$*" # [a b c] one word joined by first char of IFS
show $@ # [a] [b] [c] re-split
show $* # [a] [b] [c] re-split
Use "$@" to forward arguments (exec "$@", wrapper scripts). Use "$*" only when you want one string, e.g. a log message: log "args: $*".
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhat is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?IntermediateHow do you do search-and-replace, substrings, length and case conversion without external tools?Intermediate