help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shell script return in a makefile


From: Stephan Beal
Subject: Re: Shell script return in a makefile
Date: Mon, 14 Jun 2010 19:42:58 +0200

On Mon, Jun 14, 2010 at 4:18 PM, German Escallon <address@hidden> wrote:
First things first.  How can I know if my script succeeded or not??  I've tried reading and printing the $? environment variable.  Here's what I've tried with a script that should always fail.

e.g:
  @$(shell /path/to/my/script.sh)
  @echo "result: $$?"

That is TWO shell scripts, from the point of view of make. Change it to:

  @/path/to/my/script.sh

and it will work as you want, as long as the script itself returns non-0 for error. Do not use $(shell) to execute shell code from within a recipe (except under very unusual conditions, maybe).

 
The line always prints "result: 0", regardless of the result.

Because make sees it as a line of its own, and each logical line is a different script as far as make is concerned, and it starts a different subshell for each line.
 
When I run this same script on the console, and then echo the $? variable, I always get the error code I'm hoping for.

ECHOing the error code will return code 0 (regardless of what it prints) and will not cause make to exit.

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]