Most of the time you want $@
. But a use I've found... Let's say you're creating a script that creates another script (e.g. to be executed on a remote server). You have an array with commands, and you want to pass $@
to the command:
f() { cmds+=("some-command ${@@Q}")}f a b c
But this way 3 elements are added to the array: some-command a
, b
, and c
. What you want is:
cmds+=("some-command ${*@Q}")
Or even:
cmds+=("some-command${@+ ${*@Q}}")