Notice that we return from a loop, which is redirected.
I don't know, if I should worry about the write buffer of "file".
function f {
i=1
while :
do
echo aaaaaaaaaaaaabbbbbbbbbbbbbbbbb
((i++))
if [ $i -gt 3 ]
then
return # return while redirected
fi
done >> file # writing to file
}
f
NOTE: I am aware that this function could be easily rewritten, so that is would not return from within the redirected loop. However this is just a simplified example for the purpose of this question.
So please, do not try to improve this code.
I am not interested in workarounds, either.
My sole question is, if there is something I should be particularly aware of. Like the file descriptor is not closed properly. Or sometimes I can expect only half of the buffer (i.e. "aaaaaa") to be written into the file.
I would like to know, if this is a very bad idea, and why? Or maybe it would work without unforeseen race conditions or similar? (but again, I don't want answers like "it is bad because you should use this-and-this pattern instead")