I am trying to run a bash -c command relying on the parent bash scripts arguments via "$@"
When running a normal command, I use "$@" and bash does the expand magic for each arg.
printf '[%s] [%s]\n' "$@"
$ ./script one "t w o"
[one] [t w o]
My first naive attempt at escaping falls over in an odd way with the $@ quotes as the parent bash appears to the "end" the current argument.
bash -c "printf '%s %s\n' \"$@\""
$ ./script one "t w o"
t w o": -c: line 1: unexpected EOF while looking for matching `"'
t w o": -c: line 2: syntax error: unexpected end of file
From there "$@" kind of defies my regular escaping tricks as nothing is really quoted, I'm guessing bash deals with the expansion at a lower exec level.
How do I use the "$@" script arguments in a bash -c one liner?
quoted_args=$(printf "'%s' " "$@")works for non ' cases but that seems like the wrong solution...bash -c 'printf "%s %s\n" "$@"' arg-zero "$@"?$0: unix.stackexchange.com/q/152391/70524