Xref: utzoo comp.unix.questions:13715 comp.sys.sequent:279 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!ndcheg!uceng!kamat From: kamat@uceng.UC.EDU (Govind N. Kamat) Newsgroups: comp.unix.questions,comp.sys.sequent Subject: Re: Possible Sh bug? Keywords: SUN4, Sequent S81 Message-ID: <1034@uceng.UC.EDU> Date: 19 May 89 03:45:22 GMT References: <1002@syma.sussex.ac.uk> Followup-To: comp.unix.questions Organization: College of Engg., Univ. of Cincinnati Lines: 32 In article <1002@syma.sussex.ac.uk> andy@syma.sussex.ac.uk (Andy Clews) writes: >% sh >$ echo $? >0 >$ if [ $? != 0 ]; then exit 1; fi >$ echo $? >0 > >Why the different value of $? at the end of each example? Which system >is at fault? Or are they both wrong :-) :-) The Sun version is right. The return code of an "if" is supposed to be 0 in case none of the branches gets executed. To avoid this behavior of the "if", you can use [ $? -ne 0 ] && exit 1 echo $? which will return a 1. >What exit status (value) should the "if" return? My understanding is >that "exit" only works in non-interactive shells (see man sh(1)), but >surely in the above, it shouldn't get as far as the "exit" anyway >because $? is 0. Exit should work the same in both interactive and non-interactive shells. Perhaps your sh(1) behaves differently. -- Govind N. Kamat College of Engineering kamat@uceng.UC.EDU University of Cincinnati Cincinnati, OH 45221, USA