Subject: Re: correct shell behaviour?
To: None <email@example.com>
From: Kevin Schoedel <firstname.lastname@example.org>
Date: 08/12/2002 01:28:35
I've just tried the examples on V7 sh, recent commercial UNIX sh, ksh88, and
ksh93 -- the latter three on Solaris 6 and Unixware 7, where each agrees
> (exit 3);echo $? $(echo $?) $?
3 3 0
>echo `echo a; exit 3` >`echo /dev/tty; exit 2` $?
All sh and ksh88 produce
but ksh93 produces
A quick test shows that ksh93's "0" is the status of the "echo a".
$ echo `cmp -s /etc/group /etc/group; exit 3` >`echo /dev/tty; exit 2` $?
$ echo `cmp -s /etc/passwd /etc/group; exit 3` >`echo /dev/tty; exit 2` $?
$ echo `if cmp -s /etc/passwd /etc/grope; then exit 3; else exit 4; fi` $?
These results are... counterintuitive.
> x=$(echo var >&2) : >/dev/null$(echo redir >&2) $(echo arg >&2)
All but V7 sh agree:
V7 doesn't perform the redirection on a ":" (a 'feature'), so it generates
But wait! If instead of ":" we run an external command, all shells agree:
If we run a builtin command, we run away screaming.
> (exit 2)
> a=`echo a; exit 3`
> echo $?
>> The expectation here is that $? refers to the `` pipeline.
>> ie it is possible to test the result of such items.
>No, absolutely not. The last list (pipeline, whatever) is the
Apparently not... but for
$ (exit 2)
$ echo $?
all do produce
"If I have not seen as far as others,
it is because I am standing in the footprints of giants."