zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@math.gatech.edu
Subject: Insidious exit status bugs
Date: Thu, 24 Sep 1998 23:41:27 -0700	[thread overview]
Message-ID: <980924234127.ZM15042@candle.brasslantern.com> (raw)

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


             reply	other threads:[~1998-09-25  6:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-25  6:41 Bart Schaefer [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=980924234127.ZM15042@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).