SSHで実行するとgrep '\;.'がgrep '\''\;.'\'''に拡張されるのはなぜですか?

SSHで実行するとgrep '\;.'がgrep '\''\;.'\'''に拡張されるのはなぜですか?
$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の引数は、コマンドの引数を拡張形式で表示する-xbashコマンドの引数です。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

おすすめ記事