Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Escaping commands for shipit.remote/local #91

Closed
timkelty opened this issue Aug 4, 2015 · 4 comments
Closed

Escaping commands for shipit.remote/local #91

timkelty opened this issue Aug 4, 2015 · 4 comments
Assignees
Milestone

Comments

@timkelty
Copy link
Member

timkelty commented Aug 4, 2015

I recently had an issue with a shipit.remote command with a $ in it:

mysql -u'xxx' -p'xxx$xx' -h'127.0.0.1' -D db_production

For this to work properly, the $ needs to be escaped (-p'xxx\$xx' ).

What is the best way to deal with this?

Is this something that shipit.remote/ssh-pool should do, or should I have to make sure my strings are escaped before I pass them to shipit.remote?

@gregberge
Copy link
Member

@timkelty hmm it should be done in the project, we already do it for quotes

@timkelty
Copy link
Member Author

After a bit more investigating, the problem is actually related to quotes.

In my example, mysql -u'xxx' -p'xxx$xx' -h'127.0.0.1' works fine on the server, because of the single quotes.

However, when shipit runs it, the acutal command is

ssh foo@server.com "mysql -u'xxx' -p'xxx$xx' -h'127.0.0.1'"

In this instance, because the outer double quotes, the dollar needs to be escaped within context of the ssh command.

@gregberge
Copy link
Member

@timkelty OK let's escape $

@nkovacs
Copy link

nkovacs commented Nov 14, 2017

It would be better to use single quotes in the ssh command, like this:

ssh foo@server.com 'mysql -u'\''xxx'\'' -p'\''xxx$xx'\'' -h'\''127.0.0.1'\'''

(The last '' could be removed, but it's simpler to just leave it.)

Since you can't have single quotes inside single quotes (even escaped), you have to close the first single-quoted string, immediately add a literal single quote (that's why it's escaped), then continue with another single-quoted part of the string.

So what you have to do is replace each single quote inside the command with '\'' (or '"'"') and add single quotes around it before passing it to ssh: https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants