It is currently Fri, 15 Oct 2021 21:47:07 GMT



 
Author Message
 Behavior of /bin/sh exit status from if ... then ... fi
On Ultrix 4.2 and AOS 4.3bsd, /bin/sh preserves the result of
the conditional of an if <expr> then ... fi such that if the test in:
        if test -f /tmp/doesntexist
        then
                echo "if clause"
        fi

returns false, then the following statement has false as prior exit status.

On SunOS 4.1.1 the exit status is reset to true.

In both cases, adding an else clause resets the exit status to true.

This makes the writing of Makefiles with embedded shellscript somewhat
unportable between these systems. On Ultrix and AOS4.3 you get a "hard"
error terminating make, on SunOS it carries on.

Is either one "correct" or is this a SysV vs BSD difference?

        -George
--
                         George Michaelson
G.Michael...@cc.uq.oz.au The Prentice Centre      | There's no  market for
                         University of Queensland | hippos in Philadelphia
Phone: +61 7 365 4079    QLD Australia 4072       |          -Bertold Brecht



 Mon, 07 Mar 1994 09:29:58 GMT   
 Behavior of /bin/sh exit status from if ... then ... fi

The Sys V behavior is correct.  The new BSD shell does not have this
bug, but it is present in the BSD sh up to and including 4.3-reno.

Chet

--
``Teach them politics and war so their sons may study medicine and mathematics
in order to give their children a right to study painting, poetry, music, and
architecture.''
Chet Ramey, CWRU  Inet: c...@po.CWRU.Edu   NeXT Mail: c...@macbeth.INS.CWRU.Edu



 Mon, 07 Mar 1994 22:07:51 GMT   
 Behavior of /bin/sh exit status from if ... then ... fi

 >On Ultrix 4.2 and AOS 4.3bsd, /bin/sh preserves the result of
 >the conditional of an if <expr> then ... fi such that if the test in:
 >   if test -f /tmp/doesntexist
 >   then
 >           echo "if clause"
 >   fi
 >returns false, then the following statement has false as prior exit status.
...
 >This makes the writing of Makefiles with embedded shellscript somewhat
 >unportable between these systems. On Ultrix and AOS4.3 you get a "hard"
 >error terminating make, on SunOS it carries on.
 >Is either one "correct" or is this a SysV vs BSD difference?

To make sure that you're portable, I highly suggest using:

        -if test -f ...

The leading dash tells make to ignore any possible error from this command.

        -Jeff
--
Jeff Beadles            j...@onion.rain.com



 Wed, 09 Mar 1994 07:31:04 GMT   
 Behavior of /bin/sh exit status from if ... then ... fi

This is what I do in psroff:

        #Uncomment if your shell's busted
        #IGNORESH = set +e ;

        blah:   foo
                $(IGNORESH) if test .... \

When make invokes a rule, it invokes the shell with the shell option
"-e" set, telling the shell script to abort when a command returns
non-zero.  And, as noted, some versions of the bourne shell mistakenly
abort when the conditional in an if statement returns non-zero.
(This isn't a BSD/USG difference per-se.  And *is* a bug)

By using the "set +e", you can still abort by explicitly doing an exit -
which is desirable if the shell script determines something is wrong.
(As if the shell script was invoked directly without being invoked
by make)

Ie:
        $(IGNORESH) if test ! -f file ; \
                gorzumplatz > file
                if test $? != 0 ; \
                then \
                        rm -f file ; \
                        exit 1 ; \
            ...

--
Chris Lewis; UUCP: ...!{cunews,uunet,latour}!ecicrl!clewis;
DOMAIN: cle...@ferret.ocunix.on.ca; Phone: Canada 613 832-0541
Psroff info: psroff-requ...@ferret.ocunix.on.ca
Ferret mailing list: ferret-requ...@ferret.ocunix.on.ca



 Thu, 10 Mar 1994 12:53:24 GMT   
 
   [ 4 post ] 

Similar Threads

1. Exit status in /bin/sh

2. #!/bin/sh #!/usr/bin/sh can I do both for 2 diff machines

3. Strange behavior of /bin/sh..

4. Odd /bin/sh behavior on HP-UX 9.01

5. Very bizarre /bin/sh behavior

6. exit status of pipeline in sh/csh

7. subprocess exits with status 2, and sh script stops

8. sh: trap 0 and exit status

9. Getting exit status from backgrounded job in sh


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software