$cat test.sh
ssh HOST -l root -o StrictHostKeyChecking=no -q "/bin/bash -l -c /bin/env | grep -w PATH | grep '\;.'"
$bash -x test.sh
+ ssh HOST -l root -o StrictHostKeyChecking=no -q '/bin/bash -l -c /bin/env | grep -w PATH | grep '\''\;.'\'''
答案1
这与 SSH 无关。 bash 的参数-x
是 bash 命令的参数set
,它以扩展形式显示命令的参数。这就是双引号字符串显示为单引号字符串的原因。
$ cat test.sh
echo "here are 'some single quotes' inside double quotes"
$ bash -x test.sh
+ echo 'here are '\''some single quotes'\'' inside double quotes'
here are 'some single quotes' inside double quotes