Colorized Terminal Outputs: Difference between revisions

From Leo's Notes
This page was last edited on 15 June 2020, at 00:29.
http://leo.steamr.com/2011/01/color-ize-your-scripts/
 
m Added category
 
Line 57: Line 57:
$ echo "\033[31;44mRed with a Blue Background Text\033[0m"
$ echo "\033[31;44mRed with a Blue Background Text\033[0m"
}}
}}
{{Navbox Linux}}[[Category:Linux]]

Latest revision as of 00:29, 15 June 2020

Coloring Output

To color your shell script output, you will need to echo out an escape sequence that looks something like \033[$color1;$color2;$stylem.

You can specify one or more colors or styles by delimiting 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:

Style Code
Normal 0
Bold 1
Underline 4

Examples

Try these examples by echoing them in a terminal.

To print something as underlined green:

$ echo "\033[33;4mYellow Underlined Text\033[0m"

To print something underlined, red, with a blue background:

$ echo "\033[31;44;4mRed Underlined with a Blue Background Text\033[0m"

To print the above without the underline, just remove the '4' style

$ echo "\033[31;44mRed with a Blue Background Text\033[0m"