Parameter expansion toolkit bash
basename, strip extension, and global replace without spawning sed/basename
f=/var/log/app.log.gz; echo "${f##*/}" "${f%.*}" "${f//log/LOG}"
more bash
all 12 commands →
Regex capture with BASH_REMATCH
[[ $s =~ ^([0-9]+)\.([0-9]+) ]] && echo "${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
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: $?"