Home > Software design >  ssh bash with whitespace?
ssh bash with whitespace?

Time:02-05

Can anyone explain, please, why this command echoes an empty line instead of "abc"? I'm stuck with this. I know there are multiple ways of reaching the same goal but please also explain why this command does not print "abc" and why it's wrong.

ssh 127.0.0.1 bash -c "echo abc"

CodePudding user response:

You effectively lose a level of quoting when you execute commands via ssh. You would need to write instead:

ssh 127.0.0.1 'bash -c "echo abc"'

Without those outside quotes, the command you're running on the remote system is:

bash -c echo abc

Here you're running the command echo, with $0 set to abc.

  • Related