Subject: Re: sh problem
To: Erich T. Enke <eenke@wheaton.edu>
From: Patrick Welche <prlw1@newn.cam.ac.uk>
List: current-users
Date: 01/24/2000 22:26:53
On Mon, Jan 24, 2000 at 08:24:37PM +0000, Erich T. Enke wrote:
> I also found these results (using 1.4.1 -- I don't have access to a current
> machine, but may be useful nonetheless):
>
> sh: ! ( echo hello | grep h ); echo $?
> sh: hello
> sh: 1
> bash: ! ( echo hello | grep h ); echo $?
> bash: hello
> bash: 0
> ksh: ! ( echo hello | grep h ); echo $?
> ksh: hello
> ksh: 1
As Bruce Momjian pointed out to me, putting () in is subtly different, as it
spawns a subshell to do the pipe, whereas the bit I was complaining about
as per PR bin/9184 is that in the sh(1) manpage:
The format for a pipeline is:
[!] command1 [| command2 ...]
If the reserved word ! does not precede the pipeline, the exit status is
the exit status of the last command specified in the pipeline. Other-
wise, the exit status is the logical NOT of the exit status of the last
command.
It isn't clear to me what ! should do with the exit status of a subshell -
it seems sh takes the logical not of it correctly from your example.
Cheers,
Patrick
> >sh seems to be broken:
> >
> >quartz% ksh
> >$ echo "$PGDATA" | grep '^/'
> >/usr/local/pgsql/data
> >$ echo $?
> >0
> >$ ! echo "$PGDATA" | grep '^/'
> >/usr/local/pgsql/data
> >$ echo $?
> >1
> >$ quartz% sh
> >$ echo "$PGDATA" | grep '^/'
> >/usr/local/pgsql/data
> >$ echo $?
> >0
> >$ ! echo "$PGDATA" | grep '^/'
> >/usr/local/pgsql/data
> >$ echo $?
> >0
> >
> >That last 0 should be a 1 as per ksh shouldn't it?
> >
> >This is NetBSD/i386-current of 4 Jan (or yesterday not sure).