Regex capture with BASH_REMATCH bash
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]}"
more bash
all 12 commands →
Parallel xargs over null-delimited input
find . -name '*.log' -print0 | xargs -0 -P"$(nproc)" -n1 gzip
Check PIPESTATUS of each stage
curl -s "$url" | jq .data; echo "${PIPESTATUS[@]}"
getopts flag parsing
while getopts "n:v" o; do case $o in n) ns=$OPTARG;; v) verbose=1;; esac; done
Bound command with timeout and kill
timeout -k 5s 30s ./long_task.sh || echo "timed out: $?"
Dedicated fd for structured logging
exec 3>>audit.log; echo "$(date -Is) start" >&3; exec 3>&-