Bash

Progress Bar (basic)

admin by @admin ADMIN
just now
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Draw a single-line progress bar that updates in place. Useful for batch jobs where you know the total work count up front.
Bash
Raw
progress_bar() {
    local current="$1" total="$2" width="${3:-40}"
    local pct=$(( current * 100 / total ))
    local filled=$(( current * width / total ))
    local empty=$(( width - filled ))
    printf "\r[%s%s] %d%% (%d/%d)" \
        "$(printf '█%.0s' $(seq 1 $filled))" \
        "$(printf '░%.0s' $(seq 1 $empty))" \
        "$pct" "$current" "$total"
}

TOTAL=50
for i in $(seq 1 $TOTAL); do
    sleep 0.05               # imagine real work here
    progress_bar "$i" "$TOTAL"
done
echo   # newline after the bar
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.