Re: Why root?
Re: Why root?
- Subject: Re: Why root?
- From: Christopher Nebel <email@hidden>
- Date: Fri, 2 Aug 2002 17:41:05 -0700
On Friday, August 2, 2002, at 01:54 PM, John Delacour wrote:
At 12:41 pm -0700 2/8/02, Christopher Nebel wrote:
(What do you mean "BBEdit takes you to the user directory"? How can
you tell?)
By typing 'ls' in a new BBEdit shell window, hitting the enter key and
getting a list of items in my user directory, precisely as happens in
the Terminal window. Or by typing 'set' ditto.
Oh, nifty -- I didn't know they had that feature.
if you type do shell script "set" and check your result, you will see
all the settings for the do script command. In particular that pwd is
"/"
Well, to be accurate PWD, whatever that is, is /, but I think it
ought not to be.
The "wd" is short for "working directory", i.e., the base directory for
relative file paths. The "p" in the command "pwd" is short for
"print"; I expect sh named its variable the same thing for symmetry.
Most other things in the system use "c" for "current".
In the terminal:
[localhost:~] jd% PWD
PWD: Command not found.
[localhost:~] jd% pwd
/Users/jd
[localhost:~] jd%
Besides, if Applescript thinks my home directory is /, why does cd
take me to users/jd ? And why does the terminal not have pwd set and
Applescrips not have cwd set, and why does do shell script "set" give
me everything in upper case?
"cd" takes you to your home directory because that's what cd with no
arguments does. AppleScript knows exactly where your home directory is
(or rather, it could find out if it wanted to), it's just not going
there beforehand.
As for the pwd/PWD/cwd business, you're probably using csh in Terminal,
while "do shell script" always uses sh. The two shells differ somewhat
in the standard environment variables they set: sh defines "PWD" to
always be the current working directory, while csh uses "cwd" for the
same thing. "set" gives you a list of all defined variables; by
tradition, environment variables are named in all uppercase.
Interestingly, the reason just plain "PWD" works in sh but not csh is
that (a) you're using an HFS+ boot disk, and (b) sh isn't
case-sensitive to the degree that csh is -- it thinks you mean
/bin/pwd, which gives the same results as "echo $PWD".
Why should you take everybody to a directory that nobody's expecting
to end up in? I log in to the system as jd, so I expect to be taken
to users/jd. I'm no unix-head but from the little I have read, that's
what a unix head would expect.
And if in BBEdit I type 'sh<ENTER>' before I type 'set<ENTER>' I get
this in the list:
PWD=/Users/jd
so what am I to make of your statement that
the "sh" process that it invokes, inherits the working directory of
its parent, and the Finder launches everything with a working
directory of "/".
The Finder launches everything with a working directory of "/", but a
program can change it any time it feels like it, and presumably this is
what Terminal and BBEdit do. Script Editor, on the other hand, doesn't
muck with it, and neither does "do shell script".
My question is, why are you expecting "do shell script" to take you
anywhere at all? "do shell script" is not Terminal -- it will not use
your default shell, it will not read your shell rc files, and it will
not change the working directory. Perl and Awk also have shell
escapes, and, not coincidentally, they behave like this as well -- "do
shell script" was modeled on them. Consider the following bits of
shell:
perl -e 'print `pwd`'
awk 'BEGIN { print system("pwd"); }' < /dev/null
osascript -e 'do shell script "pwd"'
All of these will print the the directory that you happen to be in. If
"do shell script" always set cwd to ~, however, osascript would
disagree, which suggests that the existing behavior is, by Unix
definitions, correct.
Now, we do have some professional Unix-heads on staff, so I can run
this by them. In the meantime, however, my position is that "do shell
script" should behave as much as possible like the equivalents in
long-established Unix languages. BBEdit is an interesting
counter-example, but I suspect they're deliberately trying to emulate
Terminal instead. What happens if you say "echo $version" in BBEdit?
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.