Skip to content

Remote SSH commands require double escaping before hitting the DefaultShell #1082

Closed
@penguin359

Description

@penguin359

"OpenSSH for Windows" version
1.0.0.0

Server OperatingSystem
Windows Server 2016 Standard

Client OperatingSystem
Fedora 27

What is failing
Attempting to run remote commands using SSH with my DefaultShell set to powershell.exe requires escaping the command to pass through both my local shell and the Command Prompt on the remote Windows server before PowerShell handles the command. As a simple example, this is the command as run directly inside Powershell:

echo "`"hello`""

Which produces this output:
"hello"

Attempting to run the above command from a Bash script on Linux, I expect to have to use single quotes around the command to avoid Bash interpresting the double-quotes and back-ticks, but not much else:

ssh windows 'echo "`"hello`""'

It's hard to read, but that ends in back-tick, double-quote, double-quote, single-quote. However, I find that this only produces the following output:
hello`

Which seems to be due to the Command Prompt first interpreting the double-quotes before handing it off to PowerShell. Instead, I must quote the command for the Command Prompt and then for Bash in order for it to pass all the way to PowerShell unencumbered. The following command produces the correct output:

ssh windows '"echo \"`\"hello`\"\""'

This is far from intuitive and gets worse as I try to do more complex commands including pipes, where-object and foreach-object using the ?, %, and {} metacharacters.

Expected output
"hello"

Actual output
hello`

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions