akavel's digital garden

bash tricks

#!/usr/bin/env bash
set -euo pipefail
die() { echo "error: $*" >&2; exit 1; }

FOO=foo
BAR=bar

ARG1=""
while [ -n "${1:-}" ]; do
  case "$1" in
    -a|--arg1) ARG1=$2; shift;;
    *) die "Unknown arg: $1";;
  esac
  shift
done
[ -d "$ARG1" ] || die "missing --arg1 or not a directory ($ARG1)"

do_something \
  --foo "$FOO"     `# important because xyzzy` \
  "$ARG1"          `# note it's classy`

do_other          |  # can do comments after pipe sign!
  or_another -xyz |  # because foobar
  barfoo
🌱 seedling — contents of this article got classified among young, unrefined ideas that I’ve just planted—or old, unrefined ideas that need watering. If I am a diligent, caring gardener, they’ll grow into budding and maybe even ripe.
© Mateusz Czapliński 🐘 Mastodon 🐙 GitHub 🎮 Itch.io ♟️ BGG 🧶 Ravelry