An answer such as this does a good job explaining how to control passing all variables through to a command.
I wanted to explore how to do this on a per-argument basis. Observe (this was tested in zsh
):
$ program() { echo 1: $1 2: $2 3: $3; }
$ run() { program "$@"; }
$ run2() { echo `run $1`; }
$ run2 'a b' c
1: a b 2: 3:
I want a way to pass a first arg which is a string that has spaces in it, and have that spliced $@
style into another command. e.g. run2 "a b" c
should produce 1: a 2: b 3:
At this point I have solved my immediate problem because although my test code breaks when I tested it in zsh, once implemented into an actual bash script, it works.
This does indicate that maybe this relies on some intricacies in string and argument handling that are not "safe". So this is more of a request for comment on a more robust way to achieve this behavior reliably.
zsh
though – Eric Renouf Sep 23 '16 at 16:43