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?

Dave
  • 25

2 Answers2

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'
kenorb
  • 26,615
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'
gogoud
  • 1,436