<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>