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]}"
- tool
- bash12 commands
More bash commands
-
find . -name '*.log' -print0 | xargs -0 -P"$(nproc)" -n1 gzipRun N parallel jobs safely with NUL separators for names with spaces
-
curl -s "$url" | jq .data; echo "${PIPESTATUS[@]}"Inspect exit code of every pipe stage; $? only reports the last command
-
while getopts "n:v" o; do case $o in n) ns=$OPTARG;; v) verbose=1;; esac; donePOSIX option parsing with arguments; -n takes a value, -v is a switch
-
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