getopts flag parsing
POSIX option parsing with arguments; -n takes a value, -v is a switch
while getopts "n:v" o; do case $o in n) ns=$OPTARG;; v) verbose=1;; esac; done
- tool
- bash12 commands
More bash commands
-
timeout -k 5s 30s ./long_task.sh || echo "timed out: $?"SIGTERM at 30s then SIGKILL after 5s grace; exit 124 means it was killed
-
exec 3>>audit.log; echo "$(date -Is) start" >&3; exec 3>&-Open fd 3 to a file, write to it independently of stdout, then close it
-
setopt extendedglob; print -l **/*(.); autoload zmv; zmv '(*).txt' '$1.bak'zsh: list only regular files recursively, then mass-rename safely with zmv
-
set -euo pipefail; IFS=$'\n\t'Fail fast on errors, unset vars, pipe failures; split only on newline/tab
-
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT INT TERMAuto-remove mktemp dir on exit/signal; note: quote $tmp to survive spaces