[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Problems with status.
From: |
PATTON, BILLY \(SBCSI\) |
Subject: |
RE: Problems with status. |
Date: |
Thu, 13 Apr 2006 15:40:33 -0500 |
Paul,
I think you hit the nail on the head with $(EXEC_LOG ) ... || exit $?
I'm going to test now.
Thankyouverymuch :)
> -----Original Message-----
> From: Paul Smith [mailto:address@hidden On Behalf Of Paul D. Smith
> Sent: Thursday, April 13, 2006 3:14 PM
> To: PATTON, BILLY (SBCSI)
> Cc: address@hidden
> Subject: Re: Problems with status.
>
>
> %% "PATTON, BILLY \(SBCSI\)" <address@hidden> writes:
>
> pb> I may have 10 lines in my command but all are ; \ to
> make one process.
>
> Not good.
>
> pb> example
> pb> target :
> pb> @for X in variable ; do \
> pb> if [ -f $$$$X ] ; then \
> pb> $(EXEC_LOG) some_scommand ; \
> pb> fi ; \
> pb> done ; \
> pb> $(DO_SOMETHING) ;\
> pb> if [ a = b ] ; then \
> pb> bla bla bla ; \
> pb> fi
>
> pb> EXEC_LOG is failing but make is continuing to run. As
> I understand it
> pb> the last ; wins.
>
> To be precise, the exit code from a shell script is the exit
> code of the
> last command executed in the script.
>
> Unless you explicitly call exit with a different value.
>
> pb> This came to me through the K's of defunct processes.
>
> pb> Do I have to do something like
> pb> stat=0; \
> pb> @for X in xxx ; do \
> pb> $(EXEC_LOG) ...
> pb> let stat=stat+$?
> pb> ...
> pb> fi ; \
> pb> $$stat
>
> This won't work. It will just try to run the command "0" or "1" or
> whatever, which certainly doesn't exist.
>
> $ /bin/sh -c 'stat=0; $stat'
> /bin/sh: 0: command not found
>
> This is the shell, not Perl.
>
>
> Do you really want to continue to run the rest of the command once
> something fails? If so you'll have to do something similar
> to what you
> suggest.
>
> But, if you want to stop as soon as something bad happens you have two
> choices: either exit immediately, or use "set -e" in your
> shell scripts
> to tell the shell to exit as soon as some command fails (see the
> documentation for your shell to know what this means).
>
> First example:
>
> target :
> @for X in variable ; do \
> if [ -f $$$$X ] ; then \
> $(EXEC_LOG) some_scommand || exit $? ; \
> fi ; \
> done ; \
> $(DO_SOMETHING) || exit $? ; \
> if [ a = b ] ; then \
> bla bla bla || exit $? ; \
> fi
>
>
> Second example
>
> target :
> @set -e; \
> for X in variable ; do \
> if [ -f $$$$X ] ; then \
> $(EXEC_LOG) some_scommand ; \
> fi ; \
> done ; \
> $(DO_SOMETHING) ; \
> if [ a = b ] ; then \
> bla bla bla ; \
> fi
>
> Note that neither of this is effective if your commands are in a
> pipeline and one of them fails:
>
> foo | bar | baz
>
> and "bar" fails... this is very, very hard to deal with in
> normal Bourne
> shell.
>
> --
> --------------------------------------------------------------
> -----------------
> Paul D. Smith <address@hidden> Find some GNU make tips at:
> http://www.gnu.org http://make.paulandlesley.org
> "Please remain calm...I may be mad, but I am a
> professional." --Mad Scientist
>