To color your shell script output, you will need to echo out an escape sequence \033[$color1;$color2;$stylem.
You can specify one or more colors or styles, just delimit the colors or styles with a semicolon and end the list with a ‘m’.
Color is given as:
| Color | Foreground | Background |
|---|---|---|
| black | 30 | 40 |
| red | 31 | 41 |
| green | 32 | 42 |
| yellow | 33 | 43 |
| blue | 34 | 44 |
| magenta | 35 | 45 |
| cyan | 36 | 46 |
| white | 37 | 47 |
Style is given by:
| Stle | Code |
|---|---|
| Normal | 0 |
| Bold | 1 |
| Underline | 4 |
Examples:
To print something as underlined green:
\033[33;4mYellow Underlined Text\033[0m
Example:
Yellow Underlined Text
To print something underlined, red, with a blue background:
\033[31;44;4mRed Underlined with a Blue Background Text\033[0m
Example:
Red Underlined with a Blue Background Text
To print the above without the underline, just remove the ‘4’
\033[31;44mRed with a Blue Background Text\033[0m
Example:
Red with a Blue Background Text