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

Bug#1005972: sourced functions when run from set -e shells are suprising



On Sat, 19 Feb 2022 at 00:21, Thomas Stewart <thomas@stewarts.org.uk> wrote:

> I think all functions that are
> sourced should be audited to handle "set -e" and all initramfs-tools
> eventually modified to use "set -e".

Dear Maintainer,

There is a view among shell-script experts that adding "set -e"
anywhere is to be discouraged [1][2][3].

So I suggest that in any situation where remediation is required,
"set -e" should be removed, not added.

"set -e" is a fantasy to have "automatic" error handling in shell
scripts, but it breaks in all kinds of non-naive situations. The best
practice for shell scripts is to actually handle errors where they
occur:
 command || exit 1
This is not difficult, if that behaviour is desired.

It would be better if Debian policy was modified to be clearer about this.

Kind regards
David

[1] https://lists.gnu.org/archive/html/help-bash/2017-05/msg00020.html
[2] http://mywiki.wooledge.org/BashFAQ/105
[3] https://fvue.nl/wiki/Bash:_Error_handling


Reply to: