<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 &gt; /dev/null<br>    return $?<br>}<br><br><br>if is_rpm_installed fred; then echo &quot;have it&quot;; else echo &quot;nope&quot;; fi<br>
nope<br><br>if is_rpm_installed kernel; then echo &quot;have it&quot;; else echo &quot;nope&quot;; 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">&lt;<a href="mailto:splante@insightsys.com" target="_blank">splante@insightsys.com</a>&gt;</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&#39;m not sure I understand what you&#39;re trying to do, but it appears you&#39;re confusing standard out with return code. Backticks `cmd` and $(cmd) capture the standard output of a command. That&#39;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&#39;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>&quot;leam hall&quot; &lt;<a href="mailto:leamhall@gmail.com" target="_blank">leamhall@gmail.com</a>&gt;<br>
<b>To: </b>&quot;Atlanta Linux Enthusiasts&quot; &lt;<a href="mailto:ale@ale.org" target="_blank">ale@ale.org</a>&gt;<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&#39;ve looked at a few google searches and am not sure I understand what I&#39;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&#39;s actions. So far it seems as if I have to either &quot;echo&quot; 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&#39;s calls:<br><br></div><div>MY_VAR=`my_function; echo $?`<br><br></div><div>Am I looking for something that&#39;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>