Skip to content

Stop-parsing symbol on Unix-like platform doesn't support single-quoted arguments #10831

Closed

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 0

Expected 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

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Oct 18, 2019
  2. mklement0 commented on Oct 18, 2019

    @mklement0
    ContributorAuthor

    Thanks, chuanjiao10.

    I've closed this issue, because I remembered that a decision was made in #3733 (comment) that --% will not be extended to work more sensibly on Unix-like platform.

    I've created a documentation issue instead, asking that the near-uselessness of --% on Unix be documented: MicrosoftDocs/PowerShell-Docs#4963

    If you know --%'s limitations, you can still use it, however, so in the command that prompted #10219 you can simply use ssh-keygen --% "", i.e. double quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions