bash

12 commands

12 shown

Strict mode with safe IFS Fail fast on errors, unset vars, pipe failures; split only on newline/tab set -euo pipefail; IFS=$'\n\t' #bash#troubleshooting#ci Cleanup temp dir via trap Auto-remove mktemp dir on exit/signal; note: quote $tmp to survive spaces tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT INT TERM #bash#security#troubleshooting Diff two command outputs Process substitution compares two streams without temp files diff <(kubectl get cm a -o yaml) <(kubectl get cm b -o yaml) #bash#debug#k8s Read file lines into array safely mapfile -t strips newlines; handles spaces unlike for-loop word splitting mapfile -t lines < file.txt; printf '%s\n' "${lines[@]}" #bash#troubleshooting Parameter expansion toolkit basename, strip extension, and global replace without spawning sed/basename f=/var/log/app.log.gz; echo "${f##*/}" "${f%.*}" "${f//log/LOG}" #bash#performance Regex capture with BASH_REMATCH Native regex match extracts groups; note: don't quote the right-hand regex [[ $s =~ ^([0-9]+)\.([0-9]+) ]] && echo "${BASH_REMATCH[1]}/${BASH_REMATCH[2]}" #bash#debug Parallel xargs over null-delimited input Run N parallel jobs safely with NUL separators for names with spaces find . -name '*.log' -print0 | xargs -0 -P"$(nproc)" -n1 gzip #bash#performance Check PIPESTATUS of each stage Inspect exit code of every pipe stage; $? only reports the last command curl -s "$url" | jq .data; echo "${PIPESTATUS[@]}" #bash#debug#troubleshooting 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 #bash#ci Bound command with timeout and kill SIGTERM at 30s then SIGKILL after 5s grace; exit 124 means it was killed timeout -k 5s 30s ./long_task.sh || echo "timed out: $?" #bash#troubleshooting Dedicated fd for structured logging Open fd 3 to a file, write to it independently of stdout, then close it exec 3>>audit.log; echo "$(date -Is) start" >&3; exec 3>&- #bash#observability zsh recursive glob and batch rename zsh: list only regular files recursively, then mass-rename safely with zmv setopt extendedglob; print -l **/*(.); autoload zmv; zmv '(*).txt' '$1.bak' #zsh#troubleshooting
no commands match