When you run a build script, plain echo messages often feel dull - you don't know if something is still running or stuck. Adding a spinner animation and
✔/
✘ status indicators makes your script look more professional and easier to read.
In this tutorial, we will build a Bash script that:
-
Shows an animated spinner (⠹⠺⠼⠴) while tasks run
-
Prints a green ✔ when a step succeeds and a red ✘ when it fails
-
Captures logs in a file so you can debug warnings or errors
1. Basic Setup
Start with a normal shell script structure:
#!/bin/bash
BASEDIR=$(dirname $0)
cd ${BASEDIR}
We will add our spinner and logging functions here.
2. Colors for Success/Failure
We will use ANSI escape codes to color the output:
GREEN="\033[0;32m"
RED="\033[0;31m"
NC="\033[0m" # No Color
3. Spinner Frames
We will use braille-style spinner frames that rotate:
SPIN_FRAMES=(⠹ ⠺ ⠼ ⠴ ⠦ ⠧)
4. Run Command with Spinner + Logging
This function runs any command, shows the spinner, and writes logs to /tmp/build-logs/.
run_with_spinner() {
local msg=$1
shift
local i=0
# Create log directory
mkdir -p /tmp/build-logs
local logfile="/tmp/build-logs/$(date +%s)-$$.log"
# Print initial line
echo -n " $msg"
# Run command in background (logs go to file)
"$@" >"$logfile" 2>&1 &
local pid=$!
# Animate while process is running
while kill -0 $pid 2>/dev/null; do
local frame=${SPIN_FRAMES[i++ % ${#SPIN_FRAMES[@]}]}
printf "\r%s %s" "$frame" "$msg"
sleep 0.2
done
wait $pid
local exit_code=$?
if [ $exit_code -eq 0 ]; then
printf "\r${GREEN}✔${NC} %s\n" "$msg"
else
printf "\r${RED}✘${NC} %s\n" "$msg"
echo "---- LOGS ----"
cat "$logfile"
echo "--------------"
exit 1
fi
rm -f "$logfile"
}
5. Using It in a Build Script
Now replace your normal echo + command with run_with_spinner:
## App1 build
cd App1
run_with_spinner "Removing old build" <<your command for removing old build like rm -rf dist>>
run_with_spinner "Building App1" <<your build command>>
## App2 build
cd ../App2
run_with_spinner "Removing old build" <<your command for removing old build like rm -rf dist>>
run_with_spinner "Building App2" <<your build command>>
6. Example Output
When you run the script:
⠹ Building App1
⠺ Building App1
⠼ Building App1
✔ Building App1
⠹ Building App2
✔ Building App2
While the command runs → spinner rotates.
On success →
✔ green tick.
On failure →
✘ red cross and logs are printed.
Final Thoughts
This small tweak makes your shell scripts feel more interactive and professional - similar to modern CLI tools like yarn or docker.
You get clear visual feedback plus logs for debugging when needed.