applescript, shell script problem

Dar Scott dsc at swcp.com
Tue Nov 26 23:34:01 EST 2002


On Tuesday, November 26, 2002, at 08:22 PM, sean nicholas harper wrote:

> I keep getting errors when I try and execute a shell command that 
> contains
> quotes. What is the proper way of dealing with this?

function shellSH cmd
   -- Sorry, no quote marks in cmd in this version
   -- Uses sh; use full path in command
   -- And shellCommand is ignored
   put "do shell script" & quote & cmd & quote into s
   do s as AppleScript
   put result() into r
   replace numToChar(13) with linefeed in r
   return r
end shellSH

Is this the one you mean?

Look at this line:
put "do shell script" & quote & cmd & quote into s

This will create an AppleScript command like this:
do shell script "ping 127.0.0.1"

If you want to execute a command like this:
transmorgrify "Dar Scott"

It will become this AppleScript command:
do shell script "transmorgrify "Dar Scott""

...with the quotes in all the wrong places.

The quotes you pass to the shellSH function need to be quoted 
AppleScript style.  (Or we need a smarter function.)

I just tried a wild guess.  Try this:

function shellSH cmd
   -- The shellCommand is ignored.
   -- A full path is required.
   replace quote with "\"&quote in cmd
   put "do shell script" & quote & cmd & quote into s
   do s as AppleScript
   put result() into r
   replace numToChar(13) with linefeed in r
   return r
end shellSH

It worked on a quick experiment.  It seems the back slash will quote a 
quote.

Dar Scott






More information about the use-livecode mailing list