💻
Code Snippet — August 2, 2026Bash: Parallel Command Runner with Concurrency, Progress & Retry
Replace serial
for loops and opaque
xargs -P with a pure-Bash runner that gives you
live ✓/✗ progress,
configurable concurrency,
auto-retry with exponential backoff,
per-task timeout,
fail-fast for CI, and
dry-run for safety. Zero dependencies — Bash 4+ only.
# Run commands in parallel (max 2 concurrent, with 3 retries)
par-run -j 2 -r 3 "echo task1" "echo task2" "echo task3"
# From stdin — pipe find/grep results
find . -name "*.py" | par-run --from-stdin -j 8 "python -m pyflakes {}"
# With timeout and fail-fast for CI
par-run -j 4 -t 60 --fail-fast --results ./artifacts/ \\
"pytest tests/unit/" \\
"pytest tests/integration/"
# Dry-run first (safety!)
par-run --dry-run -j 4 "rsync -avz /data/ backup:/data/"
Options: -j N (max jobs),
-r N (retries),
-t SEC (timeout),
-f (fail-fast),
-d (dry-run),
--from-stdin,
--results DIRHow it works: Uses
wait -n (Bash 4.3+) for true slot-based concurrency — no semaphores, no temp files. As each background job finishes, a slot opens and the next pending task launches. Retry uses exponential backoff:
sleep $((2 ** attempt)).
💡 Drop this in ~/.bash_aliases or source it in your Makefile. Full version with self-tests: par-run --test