Plink strips out double quote marks

99封情书 提交于 2019-12-11 12:59:30

问题


I'm using PowerShell to remotely issue a command on a Linux server. I'm using plink to connect to the server.

However plink strips out double quotes in the commands I want to run. This stops those commands from working.

$user = "user"
$password = "password"
$hostname = "host"
$plinkPath = gci -Recurse | Where-Object {$_.Name -eq "plink.exe"} | select -First 1 | foreach{$_.FullName}
& $plinkPath "$User@$hostname" -pw $password "echo" "hello ab`"cdef world"

This gives the result

hello abcdef world

It lost the speech marks in between the 'b' and the 'c'.

How do I fix this?


回答1:


I hhink I've figured it, courtesy of How do I pass a literal double quote from PowerShell to a native command?. I am not entirely sure why it works, but it does:

$user = "user"
$password = "password"
$hostname = "host"
$plinkPath = gci -Recurse | Where-Object {$_.Name -eq "plink.exe"} | select -First 1 | foreach{$_.FullName}
$command = "hello ab`\`"cdef world"
& $plinkPath "$User@$hostname" -pw $password "echo" ($command -replace '(\\*)"','$1$1\"')



来源:https://stackoverflow.com/questions/34922095/plink-strips-out-double-quote-marks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!