Skip to content
zeta709 edited this page Jan 24, 2022 · 3 revisions

die

die() { printf '%s\n' "${1-}"; exit 1; }

Rationale

Why printf instead of echo?

See https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo or echo.md.

Why ${1-} instead of $*?

Because it's the simplest. According to the document above, you need to set IFS for the best reliability. However, I personally think they are overkill for a simple die function: creating a subshell would cause overhead; defining a little bit complex echo function seems inelegant. Why would you bother yourself? Just accept one argument for your die function.

Clone this wiki locally