Read file lines into array safely bash
mapfile -t strips newlines; handles spaces unlike for-loop word splitting
mapfile -t lines < file.txt; printf '%s\n' "${lines[@]}"
more bash
all 12 commands →
Parameter expansion toolkit
f=/var/log/app.log.gz; echo "${f##*/}" "${f%.*}" "${f//log/LOG}"
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