-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Related: #3734
For the stop-parsing symbol, --%, to work sensibly on Unix:
-
[preferably] either:
/bin/sh, the default shell, must be invoked, passing it a command line as a single string via-c.
As a - in my view beneficial - side effect,shwould perform globbing on unquoted tokens. -
or: PowerShell must still first interpret the tokens of the pass-through command line to strip syntactical quoting, in addition to expanding environment/shell variable references.
That may still run afoul of users' expectation that globbing should be performed.
Note: On Windows PowerShell can get away with only expanding %<name>%-style environment-variable references and then invoking the target utility without shell involvement, but that's not an option on Unix, where the shell is expected to perform tokenization up front and pass an array of literal arguments instead (with syntactical elements such as quoting characters removed).
To illustrate the problem with the current behavior (run the commands on a Unix platform):
> /bin/echo --% 'hi, mom'
'hi mom' # The enclosing single quotes were treated as *literals*Trying to pass an awk command that from sh looks like this: awk -F\" 'BEGIN { print "hi, mom" }'
> awk --% -F\" 'BEGIN { print "hi, mom" }'
/usr/bin/awk: syntax error at source line 1
context is
>>> ' <<<
/usr/bin/awk: bailing out at source line 1The array of arguments getting passed to awk breaks down as follows ($<n> represents the nth positional argument):
$1=[-F"]
$2=['BEGIN]
$3=[{]
$4=[print]
$5=[hi, mom]
$6=[}']
As you can see, the intended argument boundaries weren't respected, and the ' quoting characters were retained.
In fact, there's currently no way to make the above command work with --%, because no one is interpreting the quoting and removing the syntactical quoting characters.
Currently, only the following truly Byzantine invocation - not involving --% - can make the above awk command work:
/bin/sh -c "awk -F\\\`" 'BEGIN { print \`"hi, mom\`" }'"Environment data
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on macOS 10.12.4
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Ubuntu 16.04.1 LTS