zsh-workers
 help / color / mirror / code / Atom feed
* Insidious exit status bugs
@ 1998-09-25  6:41 Bart Schaefer
  1998-09-25 10:09 ` Peter Stephenson
  1998-09-25 15:01 ` PATCH: 3.1.4: Insidious exit status bug Peter Stephenson
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 1998-09-25  6:41 UTC (permalink / raw)
  To: zsh-workers

The following really messed me up, trying to write a script that will work
whether sh is bash or zsh.  Here's zsh 3.0.5 (3.1.4 is the same):

zagzig% echo yyy | fgrep -q xxx && echo ok
zagzig% echo yyy | fgrep -q `echo xxx` && echo ok
ok

It appears that the exit status of `echo xxx` is masking the exit status of
`fgrep -q`, but I'm not certain.  I had to do this workaround to get both
shells to behave the same:

xxx=`echo xxx`
echo yyy | fgrep -q $xxx && echo ok

Bash, of course, has an equally annoying bug:

( echo xxx | while read; do exit 0; done; exit 1; )
echo $?

Execute the above lines in bash and you'll see that $? = 1 whereas in zsh
the $? = 0.  Since I'd like to have the script exit nonzero only if the
read reaches end-of-file, I was forced into this sort of foolishness:

( echo xxx | while read; do exit 0; done; exit 1; )
ok=$?

compute some things |
while read some things
do
    [ "$some" != "$things" ] && continue
    exit $ok
done || exit 0
exit 1

In zsh, the "exit $ok" terminates the whole script with $? = 0.  In bash,
it only terminates the loop, triggering the || exit 0 clause.  In either
case, if the read gets EOF, the loop finishes sucessfully and the exit 1
then follows it.

Oof.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-09-25 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-25  6:41 Insidious exit status bugs Bart Schaefer
1998-09-25 10:09 ` Peter Stephenson
1998-09-25 10:50   ` Zefram
1998-09-25 15:01 ` PATCH: 3.1.4: Insidious exit status bug Peter Stephenson
1998-09-25 16:43   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).