Quotes within quotes within quotes in bash. :)

plug.org at 2nerds.com plug.org at 2nerds.com
Fri Jun 23 17:50:59 MDT 2006

On Fri, 23 Jun 2006, Kimball Larsen wrote:
> ssh -l username some_host_IP '/usr/bin/mysqldump -C -umysqlusername
> -pmysqlpassword DBName TableName  -w"SomeColumn like `echo -e "\047"`%015`echo
> -e "\047"`" >> /tmp/dumpFromRemote1.sql'
> ie, I use `echo -e "\047"` to get me a single quote where it needs to be to
> satisfy mysql.
> Is there something cleaner?

Maybe I'm missing something, but is there some particular reason why you 
must use single quotes around the remote command-line?  Won't double 
quotes work just as well, perhaps something like this? (minus the line 
breaks, of course):

  ssh -l username some_host_IP "/usr/bin/mysqldump -C -umysqlusername
      -pmysqlpassword DBName TableName  -w\"SomeColumn like '%015'\"
      >> /tmp/dumpFromRemote1.sql"

If you can't come up with a good way to build your mysqldump command-line 
on the client side, you might consider using a little wrapper script on 
the server side which takes simple command-line args and then builds (and 
runs) the mysqldump command-line on the server side; that might help 
work around the nested-quoting issues.


More information about the PLUG mailing list