From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11663 invoked from network); 25 Sep 1998 06:49:43 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 25 Sep 1998 06:49:43 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id CAA03339; Fri, 25 Sep 1998 02:38:17 -0400 (EDT) Resent-Date: Fri, 25 Sep 1998 02:38:17 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980924234127.ZM15042@candle.brasslantern.com> Date: Thu, 24 Sep 1998 23:41:27 -0700 X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@math.gatech.edu Subject: Insidious exit status bugs MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"CcNnI1.0.3q.Pfp2s"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4394 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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