1

I'm using a bash shell and trying to figure out the right way to write the following:

ssh mysuer@remotehost 'echo "update user set url = \'localhost\' where url = \'mydomain.com\';" >> /tmp/db.sql'

So far the above is not working.

After hitting enter the following line is a > as if it is expecting for me to close an open quote somewhere. What do I need to do so that this

update user set url = 'localhost' where url = 'mydomain.com';

is output to the remote file?

1

2 Answers 2

1

Single quotes can't be escaped, but you can end the existing one, print apostrophe (\') and open the new one.

Here is the right syntax:

ssh user@host 'echo "update user set url = '\''localhost'\'' where url = '\''mydomain.com'\'';" >> /tmp/db.sql'
0

It should work if you remove the backslashes from the single quotes inside the mysql statement:

ssh mysuer@remotehost 'echo "update user set url = 'localhost' where url = 'mydomain.com';" >> /tmp/db.sql'
3
  • That doesn't work. Instead, what is otuput to the remote file is "update user set url = localhost where url = mydomain.com;". Notice the single quotes are missing around the keywords where I want them.
    – Dave
    Mar 16, 2015 at 21:31
  • ok, try changing the single quotes inside the mysql statement to escaped double quotes.
    – gogoud
    Mar 16, 2015 at 21:39
  • here's another way: ssh mysuer@remotehost 'echo "update user set url = '"'localhost'"' where url = '"'mydomain.com'"';"'
    – gogoud
    Mar 16, 2015 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .