Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!kailand!pwolfe From: pwolfe@kailand.KAI.COM Newsgroups: comp.sys.sequent Subject: Re: Possible Sh bug? Message-ID: <2400049@kailand> Date: 19 May 89 13:20:00 GMT References: <1002@syma.sussex.ac.uk> Lines: 38 Nf-ID: #R:syma.sussex.ac.uk:1002:kailand:2400049:000:1016 Nf-From: kailand.KAI.COM!pwolfe May 19 08:20:00 1989 > /* Written by andy@syma.sussex.ac.uk in kailand:comp.sys.sequent */ > > Symm. S81 > --------- > % sh > $ echo $? > 0 > $ if [ $? != 0 ]; then exit 1; fi > $ echo $? > 1 First off, you are using the string comparison (!=) to compare numbers. You should be using "-ne". See the manpage for test(1). > What exit status (value) should the "if" return? The status 1 after the "if" command is the one returned by the last command executed, in this case "test". ("[" is a link to test - see the man page for test(1)). You can demonstrate this by: $ echo $? $ if [ $? -eq 0 ]; then echo yes; fi yes $ echo $? 0 $ if [ $? -ne 0 ]; then echo no; fi $ echo $? 1 Since $? is set so quickly, you'd be better off by assigning it to a variable, and testing and displaying that variable. I have no explanation why Sun's test returned a status of zero. It might be because of the character comparison. Patrick Wolfe (pat@kai.com, {uunet,uiucuxc,sequent}!kailand!pat) System Manager, Kuck and Associates, Inc.