You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows mangles double quotes within single quotes in arguments #3425
We spent a few minutes trying different ways of selecting and ended up figuring out that the " inside the jq string needed backlashes.
In both powershell and bash or zsh the single quotes should ensure that everything inside is not interpreted and in powershell you usually escape with backticks.
Expected vs actual behavior
The expected would be the command above but the actual command needs backslashes in powershell
@jetersen For me this works without backslashes in both zsh and bash.
Would you care to elaborate why do you think double quotes need to be escaped? Within single quotes, a double quote is a literal character without any special meaning, so I do not understand why escaping would be necessary.
Additionally, if you find one of our examples to not be working, please point us to the example from our docs and the shell in which you've found it to not be working.
Note that not all shells escape strings the same. We are aware that not all our examples work on cmd.exe, for example. However, it's hard (or impossible) to produce examples that work in every possible shell. We focus on POSIX-compatible shells, and Powershell when possible, for our examples.
gh api orgs/anorg/repos --paginate --jq '[.[] | select(.default_branch == "master")] | map({ name: .full_name })' > test.json
function not defined: master/0
CMD:
gh api orgs/anorg/repos --paginate --jq '[.[] | select(.default_branch == "master")] | map({ name: .full_name })' > test.json
'select' is not recognized as an internal or external command,
operable program or batch file.
The docs that you've linked to explicitly state that this is valid quoting style in powershell: 'hello "beautiful" soul'. The double quotes don't need to be escaped since they are within single quotes.
However, when powershell runs an executable (gh being one) and passes arguments to it, it apparently mangles double quotes. Apparently this was known for a long time 🤦
So I'm not sure what to do. How should we rewrite this example so that it works both for a POSIX shell and in Powershell with the same syntax?
changed the title [-]quotes inside jq need to be escaped with backslashes[/-][+]Windows mangles double quotes within single quotes in arguments[/+]on May 25, 2021
Activity
mislav commentedon Apr 15, 2021
@jetersen For me this works without backslashes in both zsh and bash.
Would you care to elaborate why do you think double quotes need to be escaped? Within single quotes, a double quote is a literal character without any special meaning, so I do not understand why escaping would be necessary.
Additionally, if you find one of our examples to not be working, please point us to the example from our docs and the shell in which you've found it to not be working.
Note that not all shells escape strings the same. We are aware that not all our examples work on cmd.exe, for example. However, it's hard (or impossible) to produce examples that work in every possible shell. We focus on POSIX-compatible shells, and Powershell when possible, for our examples.
jetersen commentedon Apr 15, 2021
Okay, I tested it, and it seems to be a PowerShell terminal thing.
Tested on both PowerShell 5 and 7.
jetersen commentedon Apr 15, 2021
Actually CMD does something completely different.
Powershell:
CMD:
jetersen commentedon Apr 15, 2021
Powershell and github cli is behavior is not aligned.
Based on https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.1
None of the quoting works as expected.
This includes powershell 7 on both Windows and Linux
mislav commentedon Apr 15, 2021
Ah, thanks for bringing this to our attention.
The docs that you've linked to explicitly state that this is valid quoting style in powershell:
'hello "beautiful" soul'. The double quotes don't need to be escaped since they are within single quotes.However, when powershell runs an executable (
ghbeing one) and passes arguments to it, it apparently mangles double quotes. Apparently this was known for a long time 🤦So I'm not sure what to do. How should we rewrite this example so that it works both for a POSIX shell and in Powershell with the same syntax?
jetersen commentedon Apr 15, 2021
I was not aware of this issue in PowerShell 🤔
[-]quotes inside jq need to be escaped with backslashes[/-][+]Windows mangles double quotes within single quotes in arguments[/+]jetersen commentedon Jul 23, 2021
Seems this is getting fixed in powershell though most likely only for powershell 7.2 and onward
PowerShell/PowerShell#15408
fix can't migrate title with double quotes