-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Superseded by MicrosoftDocs/PowerShell-Docs#4963
The idea behind --% is to pass command lines that use the platform-native shell through, with minimal interpretation by PowerShell.
While --% with its cmd-style environment-variable expansion is an awkward fit for Unix-like platforms to begin with, it does work in principle, but only with double-quoted arguments ("...").
However, the POSIX-like shells (such as Bash) that are native to Unix-like platforms also understand single-quoted strings (...) - verbatim strings.
--% currently doesn't support the latter.
Note that on Unix someone has to break the command line into individual arguments before passing the latter to the target process; unlike on Windows, you cannot start processes with single-string command lines in the native process-creation APIs, so truly passing a command line through isn't an option.
Steps to reproduce
# Note: From Bash itself, running
# bash -c 'echo "$1 $RANDOM"' - 'I'\''m'
# works correctly and yields something like "I'm 1234"
bash --% -c 'echo "$1 $RANDOM"' - 'I'\''m'
$LASTEXITCODE | Should -Be 0Expected behavior
The test should succeed.
Actual behavior
The test fails: The Bash command breaks due to syntax errors, and the exit code is nonzero.
Due to lack of support for single-quoted strings, PowerShell passes the following arguments to bash (enclosed in [...] here to show their boundaries):
[-c]
['echo]
[$1 $RANDOM']
[-]
['I'\''m']
Note how the '...' argument was broken in two, and how the embedded double quotes disappeared.
Environment data
PowerShell Core 7.0.0-preview.4