The following command prints foo bar
, as expected:
sh -c 'printf "$@"' -- "foo bar"
However, when called with foo
and bar
as separate arguments, it only prints foo
:
sh -c 'printf "$@"' -- foo bar
(sh
and bash
have the same behavior here)
This indicates to me that the expression "$@"
is turned into multiple parameters, leading to a call of printf foo bar
, instead of printf "foo bar"
.
- Why is this the case? I thought that quotes denote a single string?
- How can i change the
sh -c
command to get the desired behaviour (printf "foo bar"
) when passing multiple arguments?