I have a bash script where I’m trying to pass posix style arguments with quoted values down to another script called within. On the command-line I might type:
somescript --foo="bar baz"
This means with the argument having the key foo, the value is bar baz. Within somescript, you might think this would work:
innerscript "$@"
However, this re-quotes the entirety of each argument, both key and value chunked together, not just the value. So innerscript receives "--foo=bar baz" and believes you are trying to pass the key named foo=bar baz with an empty value.
It’s not good enough to tell bash “re-quote all the passed in arguments”. I need to tell bash “re-quote all passed in arguments exactly how they were quoted before“. Don’t change the position of my quotes, bro!
The problem is in
innerscript, then. There is no difference between:or, undoubtedly, a number of other alternatives. Inside
innerscript,$1(in shell notation) contains just 13 characters:--foo=bar baz. Incidentally, the same holds forsomescript; when you invoke it as shown, it does not see the double quotes. They are handled by (and removed by) the shell.To see this, try: