Saturday, February 21, 2026

set -e (was Re: single user machine, one "user" now(?) has no password (I didn't do it). [edited for clarity]

On 2026-02-21 11:47:40+0000, Crystal Kolipe <kolipe.c@exoticsilicon.com> wrote:
> On Fri, Feb 20, 2026 at 07:28:46PM -0800, Samuel wrote:
>
> > #!/bin/ksh
> >
> > set -e
>
> Do not use 'set -e' here. Or anywhere. Not in this script nor in any other
> new script that you write.

I'm surprised. Why is that? In bash at least (and per man ksh it looks
similar), I like having the script exit, rather than continuing in an
unknown state after an error. Also useful to me is set -u. Of course
there are other things to possibly keep in mind from the man pages like
the behaviors noted with the -e option (under "Command Execution" and
"set"), sometimes the "pipefail" option, just handling errors explicitly
when it's worthwhile with set +e & checking the variable $?, and maybe
others.

At one time, the Debian policy guide (or such) said all scripts except
init scripts should have set -e, and the init scripts should instead be
perfect. I realize Linux can be very different, but am not aware of the
key reasons for difference in this.

I hope to keep learning from you, Crystal, and others.
Thanks.

Luke Call

No comments:

Post a Comment