docs: add bash progress bar article

This commit is contained in:
Yorick Barbanneau 2024-06-20 00:21:11 +02:00
parent d73dd9d0fa
commit 97b9cb24ad
14 changed files with 1160 additions and 0 deletions

View file

@ -0,0 +1,29 @@
#!/usr/bin/env bash
PING_ITER=16
# shellcheck disable=2317
command() {
local -r host=${1?"first parameter must be an host"}
local -r iteration=${2?"second parameter must be an iteration number"}
local -r cmd=(ping -c "${iteration}" "${host}")
"${cmd[@]}"
}
parse_output() {
while read -r line; do
if [[ "$line" =~ icmp_seq=([[:digit:]]{1,}).*time=(.*) ]]; then
printf "séquence: %s sur %s temps:%s\n" \
"${BASH_REMATCH[1]}" \
"$PING_ITER" \
"${BASH_REMATCH[2]}"
fi
done
}
main() {
command "aquilenet.fr" "$PING_ITER" > >(parse_output)
}
main
exit 0