[ale] bash return and exit
leam hall
leamhall at gmail.com
Tue Sep 17 12:18:58 EDT 2013
Actually, when I sourced the file with the function and ran the function
with a return or exit, it exited the parent shell!
ABSG didn't seem to answer my question, though I mostly read the functions
part.
Leam
On Tue, Sep 17, 2013 at 12:13 PM, JD <jdp at algoloma.com> wrote:
> Whenever I have a question about Bash, checking the ABSG usually answers
> it.
> http://www.tldp.org/LDP/abs/html/
>
> On 09/17/2013 06:06 PM, leam hall wrote:
> > 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 $?.
> >
> > Calling script:
> >
> > MY_VAR=`my_function`
> >
> > # This fails:
> > my_function() {
> > do_something
> > return $?
> > }
> >
> > # This works:
> > my_function() {
> > do_something
> > if [ $? -eq 0 ]
> > echo 0
> > else
> > echo 1
> > fi
> > }
> >
> > The first function works if the parent's calls:
> >
> > MY_VAR=`my_function; echo $?`
> >
> > Am I looking for something that's just not in bash?
> >
> > Leam
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
--
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20130917/0b164ac3/attachment.html>
More information about the Ale
mailing list