• Sign in
  • Sign up
Elektrine
EN
Log in Register
Modes
Overview Chat Timeline Communities Gallery Lists Friends Email Vault DNS VPN
Back to Timeline !community @Badabinski
In reply to 1 earlier post
@lemmydividebyzero@reddthat.com on reddthat.com Open parent
Shell Tricks That Actually Make Life Easier (And Save Your Sanity)
Shell Tricks That Actually Make Life Easier (And Save Your Sanity)
Open parent Original URL
252
1
73
10
Badabinski in !community
@Badabinski@kbin.earth · 7d

set -e: Exit on error. Very useful, but notoriously weird with edge cases (especially inside conditionals like if statements, while loops, and pipelines). Don’t rely on it blindly as it can create false confidence. (Pro-tip: consider set -euo pipefail for a more robust safety net, but learn its caveats first.)

while I appreciate that the author mentions how weird this is, nobody is going to learn all the caveats correctly. Don’t use set -e. Don’t use set -e. Don’t use set -e. It’s a shit ass broken ass fucked feature that half of nobody understands well. Here’s a great wiki page explaining why it’s trash: https://mywiki.wooledge.org/BashFAQ/105

People like Go, and Go requires you to manually and stupidly handle every possible error case. Why not do the same for shell? It’s really quite easy:

#!/usr/bin/env bash
echoerr() { echo "$@" 1>&2; }

die() {
  message="$1"; shift
  exit_code="${1:-1}"
  echoerr "$message"
  exit "$exit_code"
}

temp_dir="$HOME/tmp"
mkdir -p "$temp_dir" || die "Failed to make persistent temporary dir $temp_dir"
lc_dir="$(mktemp -d -p "$temp_dir")" || die "Failed to make target dir in $temp_dir"

Look at that, descriptive error messages! And it doesn’t depend on a shell feature that is inconsistent between versions with no good documentation about all of the fucked up caveats.

BashFAQ/105 - Greg's Wiki

mywiki.wooledge.org
View on kbin.earth Open submitted link
10
3
0
Sign in to interact

Comments (3)

Showing 0 of 3 cached locally.
Syncing comments from the remote thread. 3 more replies are still loading.

Loading comments...

313k7r1n3

Company

  • About
  • Contact
  • FAQ

Legal

  • Terms of Service
  • Privacy Policy
  • VPN Policy

Email Settings

IMAP: mail.elektrine.com:993

POP3: pop3.elektrine.com:995

SMTP: mail.elektrine.com:465

SSL/TLS required

Support

  • support@elektrine.com
  • Report Security Issue

Connect

Tor Hidden Service

khav7sdajxu6om3arvglevskg2vwuy7luyjcwfwg6xnkd7qtskr2vhad.onion
© 2026 Elektrine. All rights reserved. • Server: 06:08:46 UTC