bug-bash
[Top][All Lists]
Advanced

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

Re: The difference between exit and return in a function


From: Paul Jarc
Subject: Re: The difference between exit and return in a function
Date: Thu, 28 Feb 2002 16:54:32 -0500
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/20.7 (i386-redhat-linux-gnu)

"Ronald van Gogh" <rogonl@hotmail.com> wrote:
> With an exit statement you should be able to leave the entire script.
> However looking at the script and the output below there seems to be
> no difference between return and exit.
...
> aa=$(mytest 1); echo "rc = $?; result = $aa"

$() commands are always executed in subshells.  So the "exit" command
in the mytest function causes the subshell to exit (but it would have
exited after the function returned anyway).  To make the parent shell
exit, you'd need to call the function outside $().  Since it's a
function, you can have the function store a value to a variable
directly rather than echoing it and then capturing the echo output.
(This will be faster, too.)


paul



reply via email to

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