Interview Prep/Shell Scripting/Variables, quoting and expansions

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: $*".

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Variables, quoting and expansions