<div dir="ltr">Very nice, all, thanks!<br><br>function is_rpm_installed() {<br> # Return 0 if the RPM is installed, otherwise 1<br> rpm -q $1 > /dev/null<br> return $?<br>}<br><br><br>if is_rpm_installed fred; then echo "have it"; else echo "nope"; fi<br>
nope<br><br>if is_rpm_installed kernel; then echo "have it"; else echo "nope"; fi<br>have it<br><br><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 17, 2013 at 12:24 PM, Scott Plante <span dir="ltr"><<a href="mailto:splante@insightsys.com" target="_blank">splante@insightsys.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:arial,helvetica,sans-serif">I'm not sure I understand what you're trying to do, but it appears you're confusing standard out with return code. Backticks `cmd` and $(cmd) capture the standard output of a command. That's separate from the return code, which is meant to be zero if all works or some other number indicating the type of error. The $? resolves to the most recent return code, but you could also do this:<div>
<br></div><div>if do_something</div><div>then echo ok</div><div>else echo sorry bub</div><div>fi<br><br>and bypass the $?</div><div><br></div><div>Sorry, in a hurry. Hope I didn't typo or make a mistake.</div><div><br>
</div><div>Scott<br><hr><div style="font-size:12pt;font-style:normal;font-family:Helvetica,Arial,sans-serif;text-decoration:none;font-weight:normal"><b>From: </b>"leam hall" <<a href="mailto:leamhall@gmail.com" target="_blank">leamhall@gmail.com</a>><br>
<b>To: </b>"Atlanta Linux Enthusiasts" <<a href="mailto:ale@ale.org" target="_blank">ale@ale.org</a>><br><b>Sent: </b>Tuesday, September 17, 2013 12:06:44 PM<br><b>Subject: </b>[ale] bash return and exit<div>
<div class="h5"><br><br><div dir="ltr"><div>I've looked at a few google searches and am not sure I understand what I'm seeing. In bash, I want to have a function do a test, and have a variable in the calling program set based on the function's actions. So far it seems as if I have to either "echo" the result or have the calling function use $?.<br>
<br></div><div>Calling script:<br><br></div><div>MY_VAR=`my_function`<br><br></div><div># This fails:<br></div><div>my_function() {<br></div><div> do_something<br></div><div> return $?<br>}<br></div><div><br></div><div>
# This works:<br></div><div><div><div>my_function() {<br></div><div> do_something<br></div><div> if [ $? -eq 0 ]<br></div><div> echo 0<br></div><div> else<br></div><div> echo 1<br></div><div> fi<br>}<br><br></div>
<div>The first function works if the parent's calls:<br><br></div><div>MY_VAR=`my_function; echo $?`<br><br></div><div>Am I looking for something that's just not in bash?<br><br></div><div>Leam<br><br><br></div><div>
-- <br><div><a href="http://leamhall.blogspot.com/" target="_blank">Mind on a Mission</a></div>
</div></div></div></div>
<br></div></div><div class="im">_______________________________________________<br>Ale mailing list<br><a href="mailto:Ale@ale.org" target="_blank">Ale@ale.org</a><br><a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br><a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br></div></div><br></div></div></div><br>_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div><a href="http://leamhall.blogspot.com/" target="_blank">Mind on a Mission</a></div>
</div>