Printing dots to show progress while a process runs, in bash


Use this when you have a long-running process in a bash script but want to show just progress dots (.) to the user while it runs.

# Start your long-running task in the background (&), then capture the Process ID of the task
sleep 5 & 
PID=$! 

# Loop and print dots while the process is running. Note use of printf which won't add a newline 
# character to the dot, so it just appends each one on the same line. Kill -0 just tests if
# the PID still exists; when it no long does because the background process finished, the loop ends.
while kill -0 $PID 2>/dev/null; do
    printf "."
    sleep 0.5
done

echo " Done!"

2026/08/17