MicrosoftDocs / terminal

Creative Commons Attribution 4.0 International
467 stars 170 forks source link

Add more notes to escape semicolons in PowerShell #765

Closed carlos-zamora closed 1 month ago

carlos-zamora commented 1 month 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 1 month 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 1 month 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 1 month 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
# From cmd.exe, the ` (backtick) would have to be removed.
wt.exe powershell -NoExit -Command "Get-Date\; `$PROFILE"

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 '...'.