by BoingBoomTschak · 2w ago · 0 comments
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... 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 ... 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.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