MicrosoftDocs / terminal

Creative Commons Attribution 4.0 International
475 stars 183 forks source link

Add more notes to escape semicolons in PowerShell #765

Closed carlos-zamora closed 6 months ago

carlos-zamora commented 6 months ago

There were already a few of these notes in the page, so I just went ahead and added them to any other PowerShell examples that use a semicolon.

Closes #763

learn-build-service-prod[bot] commented 6 months ago

Learn Build status updates of commit a057517:

:white_check_mark: Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md :white_check_mark:Succeeded View

For more details, please refer to the build report.

For any questions, please:

learn-build-service-prod[bot] commented 6 months ago

Learn Build status updates of commit e4e55bc:

:white_check_mark: Validation status: passed

File Status Preview URL Details
TerminalDocs/command-line-arguments.md :white_check_mark:Succeeded View

For more details, please refer to the build report.

For any questions, please:

mklement0 commented 6 months ago

Thanks for tackling this, but the update doesn't address the gist of #763, which wasn't about how to prevent PowerShell from interpreting a ; meant to be interpreted by wt.exe, but the inverse:

How to prevent wt.exe from interpreting a ; meant for a different program - such as the PowerShell CLI - for which a command line is being passed.

Such ; characters must be escaped as \;, irrespective of what program is being invoked and - that's the surprising part - this escaping is even necessary for ; characters inside "..."-enclosed arguments.

E.g.:

# From PowerShell or cmd.exe
wt.exe powershell -NoExit -Command "Get-Date\; 1 + 2"

Note how ; must be escaped as \; in order for wt.exe to pass it through to powershell.exe, despite being inside a double-quoted string. From PowerShell's perspective, ; does not require escaping inside "..." or '...'.