DevOps · Flashcard

Inside double quotes, how do "$@" and "$*" differ?

  • A"$@" expands each positional parameter as a separate word, "$*" joins them into one
  • B"$@" joins all positional parameters into one word, "$*" expands each separately
  • C"$@" expands only the first positional parameter, "$*" expands every one after it
  • D"$@" strips empty positional parameters entirely, "$*" keeps them as blank words

Why this is the answer

"$@" keeps each argument as its own word (the safe way to forward args); "$*" joins them into a single word separated by the first IFS char (space by default). Option two reverses them. Option three is false — $@ expands all args, not just the first. Option four invents an empty-stripping rule that neither form has.

Official docs
Study in Gnoseed →