Hacker News new | ask | show | jobs
by BoingBoomTschak 11 days ago
An administration sh script without `set -eu` in 2026? I also suggest shellcheck linting.
3 comments

I’m pretty sure set -eu is for bash; the script is written in bourne.
set -eu is POSIX sh. You're probably thinking about set -o pipefail (which is POSIX 2024 but not supported everywhere yet).
On FreeBSD 15.1:

man sh

    ...
    -e errexit
             Exit immediately if any untested command fails in non-interactive
             mode...

    -u nounset
             Write a message to standard error when attempting to expand a
             variable...
You learn something new every day : )
Both `set -eu` and `shellcheck` tools are overrated.

I have used `shellcheck` against many of my scripts and for 'well think and designed' scripts its like a 'false positive generator' tool that only waste my time.

I mean ... POSIX /bin/sh is a language like any other - like Python - like Perl ...

I have been writing scripts since 20+ years in POSIX /bin/sh tools and thinking and knowing what and how a thing can fail always wins.

... and as FreeBSD has ZFS Boot Environments (and even UFS Boot Environments) - no matter what fails and where - You are always protected from failures.

The `set -eu` is treated like some magic 'Save Game' thing - that after You set it in a script - You are always protected from everything ... You are not.

A command that will wipe Your entire / filesystem can succeed without an issue and You will see zero errors.

Regards,

vermaden

This is how much bullshit it is:

    root@150:~ # head -2 pkgbase
    #! /bin/sh
    set -eu

    root@150:~ # sh pkgbase 
    pkgbase: 1: parameter not set
    pkgbase: VER_REG: parameter not set
    root@150:~ # sh -x pkgbase
    + set -eu
    + ARG_BOOT=yes
    + trap __clean 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    pkgbase: 1: parameter not set
    + __clean
    + umount -f /boot/efi
Could not even handle 'trap' signals ...
You're supposed to

  trap 'exit 1'  INT HUP TERM...
  trap '__clean' EXIT
mate. set -eu is simply mandatory even if doesn't solve 100% of sh's jankiness.