Escape From "Do Shell Script"

My brain is fried and I can’t escape.

I want to execute the following. I’ve broken and indented the quotes within quotes in hopes of making it comprehensible.

To describe it backwards…

The MySQL command.

.must be executed by the shell command.

.which in turn must be ssh’d to another host.

.which must in turn be executed from within AppleScript.

I’m lost in quote land can’t figure out to parse this mirrors-in-mirrors wilderness of nested quotations in a way that’s actually executable.

Anyone care to help?

Thanks,
Bryan

AppleScript: 2.1.2
Browser: Safari 533.19.4
Operating System: Mac OS X (10.6)

You just need to escape ‘inner’ quote chars.
Insert a backslash before each quote, except the first and last:

set this to "it's a \"quoted\" string"

Do you realy need double quotes? If you’re using single quotes you can use ‘quoted form of’ like this

set theString to "I'm containing a quote"

do shell script "echo " & theString --result in a error
do shell script "echo " & quoted form of theString -- will return theString

Also I have a MySQL Script object that could be usefull…

Also when no ssh certificates are installed (need password) you could use this code as well

set sshUser to "sshuser"
set sshPasswd to "sshpasswd"
set sshServer to "server"
set externalCommand to "/usr/local/mysql/bin/mysql -u mysqluser -pmysqlpasswd -e 'show databases'"


set thecommand to "(echo \"spawn ssh"
set thecommand to thecommand & " " & sshUser & "@" & sshServer
set thecommand to thecommand & " " & externalCommand & "\" ;"
set thecommand to thecommand & "echo \"expect {\" ;"
set thecommand to thecommand & "echo \"\\\"Password:\\\" {send \\\""
set thecommand to thecommand & sshPasswd
set thecommand to thecommand & "\\\\r\\\" ; exp_continue }\" ;"
set thecommand to thecommand & "echo \"\\\"yes/no?\\\" {send \\\"yes\\\\r\\\" ; exp_continue }\" ;"
set thecommand to thecommand & "echo \"eof\" ;"
set thecommand to thecommand & "echo \"}\" ;"
set thecommand to thecommand & ") | expect"

do shell script thecommand