Colors in Bash
Terminal output does not have to be monochrome and hard to parse. Modern CLI tools heavily rely on ANSI color codes to communicate state, severity, and context.
If you are building Bash scripts, DevOps utilities, monitoring tools, or internal automation, adding semantic colors can:
- Improve readability
- Reduce troubleshooting time
- Highlight critical states instantly
- Make your tool feel production-grade
ANSI escape sequences allow you to control text formatting directly in the terminal. For example:
echo -e "\033[32mSuccess\033[0m"
This prints the word Success in green and resets formatting afterward.
Why Terminal Colors Matter
Color in CLI environments is not decoration — it is information encoding.
Humans process color faster than text. In high-volume logs or monitoring outputs, this reduces cognitive load and speeds up incident response.
Well-implemented color schemes:
- Improve log scanning efficiency
- Reduce operational mistakes
- Standardize communication across teams
- Increase perceived professionalism of your tool
Most Common Terminal Colors — And When to Use Them
There is an informal but widely adopted convention across Unix tools, CI/CD systems, and DevOps environments.
Green — Success / Healthy State
Green indicates successful execution or a healthy system condition.
When to Use Green
- Completed actions
- Running services
- Passed validation
- Enabled configurations
Example
echo -e "\033[32m[OK] Service started successfully\033[0m"
Red — Error / Failure
Red communicates critical issues that require attention.
When to Use Red
- Failed commands
- Fatal errors
- Exit code ≠ 0
- Interrupted processes
Example
echo -e "\033[31m[ERROR] Database connection failed\033[0m"
Yellow — Warning / Attention Required
Yellow signals non-fatal problems or degraded conditions.
When to Use Yellow
- Deprecated features
- Missing optional configuration
- Fallback logic activated
- High resource usage
Example
echo -e "\033[33m[WARNING] Using default configuration\033[0m"
Blue — Informational Output
Blue is commonly used for structured informational messages.
When to Use Blue
- Usernames
- Hostnames
- Service names
- Informational headers
Example
echo -e "\033[34mUser: deploy\033[0m"
Cyan — Debug / Verbose Output
Cyan is often used for technical or verbose output.
When to Use Cyan
- Debug mode
- Variable values
- Detailed logs
- Execution tracing
Example
echo -e "\033[36m[DEBUG] Variable x=42\033[0m"
ANSI Color Code Reference (Standard 8 Colors)
| Color | Code | Usage |
|---|---|---|
| Black | 30 | Rarely used |
| Red | 31 | Error |
| Green | 32 | Success |
| Yellow | 33 | Warning |
| Blue | 34 | Info |
| Magenta | 35 | Special tags |
| Cyan | 36 | Debug |
| White | 37 | Default light |
Reset formatting:
\033[0m
Recommended variable definitions in scripts:
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
CYAN="\033[36m"
RESET="\033[0m"
Best Practices for Using Colors in Production Scripts
- Never forget to reset formatting.
- Do not overload output with too many colors.
- Keep semantic consistency (green=success, red=error).
- Use
printffor predictable behavior. - Provide a
--no-colorflag for CI/CD pipelines. - Detect non-TTY environments before enabling color.
Example detection:
if [ -t 1 ]; then
ENABLE_COLOR=true
fi
Try It Yourself: Interactive ANSI Color Tester
Reading about ANSI color codes is useful — but seeing them in action makes everything click instantly.
Instead of memorizing escape sequences, you can experiment directly with standard colors, 256-color mode, and full 24-bit TrueColor support using the interactive tester below.
This tool allows you to:
- Instantly preview color output
- Generate copy-ready Bash variables (e.g.
RED="\033[31m") - Experiment with 256-color values (0–255)
- Create precise RGB combinations for modern terminals
- Learn the exact syntax you need for production scripts
Whether you’re building a logging framework, a monitoring script, or a CLI utility, this hands-on tester helps you move from theory to implementation in seconds.
Scroll down and start experimenting — your terminal output is about to get an upgrade.
Advanced ANSI Color Tester
Test standard colors, 256-color mode, or TrueColor (24-bit RGB). Copy the generated Bash code directly into your terminal script.
1️⃣ Standard 8 Colors
Sample Text
2️⃣ 256-Color Mode
Enter a number between 0 and 255:
Sample Text
3️⃣ TrueColor (24-bit RGB)
Enter RGB values (0–255):
R G BSample Text
Other articles on my blog:










