Re: Scripting Additions: Embracing the Horror of Unix
Re: Scripting Additions: Embracing the Horror of Unix
- Subject: Re: Scripting Additions: Embracing the Horror of Unix
- From: Oliver Sun <email@hidden>
- Date: Sat, 2 Feb 2002 16:13:01 -0500
Date: Thu, 31 Jan 2002 23:17:16 -0700
From: garbanzito <email@hidden>
at 2002 01 31, 17:55 -0500, they whom i call Oliver Sun wrote:
Am I understanding you correctly that you are trying to pass a
string from AppleScript to a shell script, which may possibly have
spaces or other special characters?
[...]
If so, you will want to use single quotes, which are even stronger
than the double quote.
yes. i know too little about this. does the status of single
or double quotes change when the command line arguments
aren't passed by a shell?
might it be better than "shell variable" to say "environment
variable", since "do shell script" doesn't invoke a shell?
i'm not even sure if environment variables are expanded in
command arguments if they're invoked by execv() (or whatever
Apple does in "do shell script" -- detailed docs would be
appreciated). in any case, don't expect .tcshrc or whatever
to have any effect on "do shell script".
It appears upon some inspection that "do shell script" actually calls
the default shell "sh" as a non-login shell.
That is, AppleScript uses your current login with OS X, so all your
environment variables are already set according to your OS X defaults
(or possibly your .profile, I will have to test some more). This is in
contrast to Terminal.app, which apparently creates a new login shell of
your choice (and logs you in automatically) for each new terminal
window, and then proceeds to execute any login scripts which you have
set up for your particular choice of shell.
One detail of note: your current working directory is set to "/".
To inspect the condition of the environment variables, you can run a
script:
do shell script "set > ~/Documents/doShellSettings"
which will deposit the contents of all your environment variables into
the file "doShellSettings" in your "Documents" folder. You should see
that
$0=sh
Meaning that the call used to create this environment was "sh".
Compare to the output in your login shell. At the terminal prompt, type:
set
In my case, I happen to use "/bin/zsh", and the value of my calling
argument is:
$0=-zsh
The '-' signifies that this was a login shell, in which case any
.login-type configuration script will also be executed automatically).
Single quotes '/Users/Me/Documents/My Funny Stuff/WTF$CK' will
literally quote all that. In fact, you can quote double quotes
within single quotes in the shell. You will, of course, have to deal
with the problem that the double quote itself needs to be escaped or
otherwise handled in AppleScript.
yeah, and should the single quote appear in a file name
(perhaps more common than double quote, since it's a
stand-in for apostrophe), you'd need to escape it too.
Mixing apostrophes and quotes seems to be problematic all-around, due in
large part to the differences in the way the Script Editor chooses to
handle them as opposed to the way POSIX does. Anyhow, I would be
interested in reading about any Q.D. workarounds that anyone here might
come up with. ;)
--
steve harley email@hidden
Cheers,
Oliver