bug-bash
[Top][All Lists]
Advanced

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

Re: return value ignored sometimes when returning from within a loop


From: Edward Welbourne
Subject: Re: return value ignored sometimes when returning from within a loop
Date: Wed, 07 May 2003 11:15:00 +0200

> This is covered in the bash FAQ, entry E4.

and where is the bash FAQ ?  It isn't mentioned in the man page, nor
can I find it in the info or via a search on www.gnu.org/directory/.
It is not sufficient that a feature be documented: it is necessary
that users be able to find the documentation when dealing with matters
to which it is relevant.

Having seen various other variants on the theme, I can now guess that
what's happening is: use of I/O redirection causes while...do...done
to happen in a subshell (familiar truth from some other gotchas) and
the return statement merely causes the while...do...done to terminate,
not the function, with success or failure according to the return
value; and the reason it managed to work when I internalised the
failure returns was that the while...do...done was the last execution
chain in the function, so its status is what the function returned.

It would be nice if the documentation of function and/or return noted
that return from within a sub-shell doesn't return from the function;
and ideally noted (though this is stated elsewhere) that pipelines run
their fragments in subshells.

        Eddy.




reply via email to

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