Concept Flow - Color output (ANSI escape codes)
Start Script
Define Color Codes
Print Text with Color
Reset Color
End Script
The script starts by defining color codes, then prints colored text, and finally resets the color to normal.
RED='\033[31m' RESET='\033[0m' echo -e "${RED}Hello in Red${RESET}"
| Step | Action | Variable/Code | Output | Notes |
|---|---|---|---|---|
| 1 | Define RED color code | RED='\033[31m' | No output | Sets RED to ANSI code for red text |
| 2 | Define RESET code | RESET='\033[0m' | No output | Sets RESET to ANSI code to reset color |
| 3 | Print colored text | echo -e "${RED}Hello in Red${RESET}" | Hello in Red (in red color) | Text appears red in terminal |
| 4 | End script | Script ends | No output | Colors reset to normal |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| RED | undefined | \033[31m | \033[31m | \033[31m |
| RESET | undefined | undefined | \033[0m | \033[0m |
Use ANSI escape codes to color terminal output.
Define color codes as variables like RED='\033[31m'.
Use echo -e to print colored text: echo -e "${RED}text${RESET}".
Always reset color after printing with RESET='\033[0m'.
Without reset, terminal color stays changed.