Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ssh bash with whitespace?

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"

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading