On Tue, Jul 6, 2021, at 8:07 AM, lisa-asket@perso.be wrote:
> With ` set -e` the script will exit immediately if a command exits with a
> non-zero status.
Except when it doesn't.
https://mywiki.wooledge.org/BashFAQ/105
> I suppose it makes sense to exit a function with a proper exit status.
Even if you do not care about the exit statuses of arbitrary pipelines
in the middle of programs, you should make sure your programs exit
with the correct status themselves.
> One might also convert the `return` statement to an `echo` statement -
> that way the function output
>
> could be captured using $() braces,
>
>
>
> What do you think?
I think this does not make any sense. Replacing a 'return' with
an 'echo' would cause your function to terminate with the wrong
exit status and possibly alter its control flow. Programs should
not print their exit statuses, anyway. Imagine this.
$ printf '%s\n' hi
hi
0
Exit statuses can be inspected with $?, if desired.
--
vq