Re: Scripting the Location
Re: Scripting the Location
- Subject: Re: Scripting the Location
- From: Axel Luttgens <email@hidden>
- Date: Sat, 06 Sep 2003 11:27:24 +0200
(Reposting, as I did a mistake and directed my reply to the original
sender. My apologies)
Paul Berkowitz wrote:
[snip]
A follow-up: why does the Terminal not see it as an error? Does tcsh simply
receive stderr as well as (instead of) stdout without murmur, while
AppleScript's sh/bash receives only stdout?
(As far as I know, this has not been precisely answered. I'll thus try
to bring my humble contribution; please agree my apologies if too obvious)
In fact, THERE IS an error.
Just let's try this in the Terminal:
[ALTi:~] luttgens% scselect; echo $?
usage: scselect [-n] new-set-name
Defined sets include: (* == current set)
* 0 (FUSL)
1 (Home)
2 (ULg)
1
As you know, $? contains the status code returned by the last command
performed.
Status should be 0 to indicate a successful completion.
But here we have a 1, very likely to indicate a bad argument list; hence
the first line ("usage:..."). [1]
Then comes the usual behavior of 'do shell script'.
If the unix code ends with no error (status = 0), 'do shell script'
returns the standard output.
In case of error (status /= 0), 'do shell script' returns stderr and
triggers an error, based on the status code, that you can catch through
a 'try/on error/end try' construct. [2]
HTH,
Axel
[1] On could speak about an "interface laziness" in the case of the
scelect command; in earlier Unix times, one would have expected
something like:
[ALTi:~] luttgens% scselect; echo $?
Bad argument count
1
[ALTi:~] luttgens% scselect -?; echo $?
usage:
scselect -l - list defined sets
scselect [-n] new-set-name - (don't ask me, I didn't
investigate ;-) )
0
[ALTi:~] luttgens% scselect -l; echo $?
Defined sets include: (* == current set)
* 0 (FUSL)
1 (Home)
2 (ULg)
0
That is, scselect's implementors decided to fuse 'scselect', 'scselect
-?' and 'scselect -l'.
Why not? It may prove handy as a shortcut for an heavy usage.
On the other hand, this is an additional convention too. Remember those
commands that didn't use the conventional '-' to precede option letters
and broke lots of shell scripts...
[2] This leads us towards some unix commands that erroneously return
with a non-null status code. From ''do shell script"'s point of view,
there is an error, while truly there is none...
_______________________________________________
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.