Quotes withing Quotes within Quotes within Quotes

OK,

I’m building a very long shell commmand in my ASS program and have run into an issue where I’m echoing a line into a script using “do shell script.”

I’ve run into a snag. The command requires that the actual text echoed into the file be quoted with single quotes, since the command itself is in double quotes. However, within that command, there’s two more layers of quoting. I CAN use the escaped double quotes and get them to print to stdout, but within THAT set of double quotes, there’s another string (a POSIX Path) that needs to be quoted and no matter what I can’t get the path to be quoted. Enclosing the single quotes in double quotes won’t get them to print. Escaping the single quotes with a backslash won’t work. I think I might be out of options. Here’s how it’s constructed:

do shell script "/bin/echo 'spawn /usr/bin/command -options" & space & "\"" & "Subcommand" & space & "'" & variable that expands to quoted POSIX Path & "'" & space & "-more command options" & space & variable & space & "-more options\"" & space & variable & "moreoptoins" & space & variable & "string' >> ~/tmp/output.tcl"

The quotes I’m having issues with are the ones surrounding “'” & variable that expands to quoted POSIX Path & “'”

When the command is constructed, these single quotes simply don’t print. Trying to escape them with a "" results in a compile failure.

Anyone have any solutions for a complex issue like this one?

You might try

quoted form of (yourthing here)

Thanks for the reply Adam, I have tried the quoted form of & variable that expands to quoted POSIX Path &

and still it won’t print the single quotes where i want them.

Remember that you can save the text of your script in pieces as variables and then assemble them in the command by name. You can include returns in the text that will become the script so it behaves as a series of terminal commands. This might be a better approach than what you’re doing.

What Adam says is true. Crunching your text like that, makes it hard to debug unless you’re an extreme pro. Also, the two do shell scripts have got to go. Do one, get the result and put it in the other.

Edited: note that setting a variable only takes about one tick maximum.

gl,

The two do shell scripts are simply a mistake - I’ll edit the post.

I have no choice but to crunch the text like that. It’s not an option, sorry to say.

The extra “do shell script” command was typo, I believe. (Been talking to Dean about this.)

Here’s what I gave him:

  1. A real shell script to which he can send his arguments. They will be processed correctly, and the external script is much easier to play with if he needs to. This also relocates his non-preference, temporary data to a better place (/private/tmp/$UID/MacHelpMate). If the app crashes or something else goes wrong, and it can’t clean up after itself, the OS will be able to deal with the wreckage.
  1. And here’s the AppleScript code that calls it:
do shell script (quoted form of ((POSIX path of (path to me)) & "Contents/Resources/script_name.sh")) & space & quoted form of PROXY_COMMAND_PATH & space & PROXY_PORT & space & SHARING_USER & space & CONTROL_KEY

edit: clarity