help-make
[Top][All Lists]
Advanced

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

Re: Re: testing returnvalues


From: Chen Jun (陈军)
Subject: Re: Re: testing returnvalues
Date: Tue, 23 Oct 2007 09:44:43 +0800

Hello, Brian Dessent, 
 
  Thank you Brian. Although I'm not the questioner, I have to appreciate that your answer is very complete and understanding.
 
======== 2007-10-23 08:51:49 You wrote: ========
 
k wayne wrote:
 
> someTarget: dependencies
>  <tab > if [ "`/bin/sh -c 'myCommand --options -asdf'`" -eq "5" ]; then fail fi
 
A couple of things here.  When you say "return value", do you mean the
exit status code (an integer that is typically zero for success,
otherwise failure) or do you mean some text that the process outputs to
stdout?  The shell backtick captures the latter, whereas the former is
stored in the shell value $?.  Also, explicitly calling the shell should
not be necessary as make does this for you.  How about just:
 
someTarget: dependencies
myCommand --options -asdf; \
if [ $$? -eq 5 ]; then \
echo "it was 5"; \
else \
echo "it wasn't 5"; \
fi
 
 
Note: If you want to access shell variables like $? you have to double-$
because otherwise make would try to expand them before passing the
command to the shell.  Also note that you have to write shell commands
as if they were all one single command (so that make invokes them all
with one call to "sh -c 'everything'") but that doesn't mean you have to
stuff it all on one physical line.
 
Finally note that make will take the final exit code of the last command
executed in the composite shell fragment as the status for the entire
target rule, so make sure to propagate a success/failure to make as
appropriate.
 
Brian
 
 
_______________________________________________
Help-make mailing list
address@hidden
 

= = = = = = = = = = = = = = = = = = = = = =

Best Regards

              Chen Jun (陈军)
              address@hidden
               2007-10-23

reply via email to

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