To change the colour of the Linux terminal output, you can modify the colour codes for the various elements in the terminal.
The most common way to do this is by using ANSI escape codes, which are special sequences of characters that control the formatting and coloring of text in the terminal.
Escape Character: The escape character is represented as \e
or \033
and signals the beginning of an escape code in many programming languages and terminal emulators. It's a special character that indicates that what follows is a control sequence, not regular text.
Control Sequence: The control sequence is enclosed within square brackets [
and specifies the text formatting or colour changes. It consists of several components, separated by semicolons, that dictate the appearance of the text.
Formatting Options (Optional):
1
: This part indicates bold or increased intensity for the text. If included, the text will appear in a bold font style.Semicolon Separator: The semicolon ;
separates different properties within the control sequence.
Colour Code:
32
: This part indicates the text colour. Colour codes for foreground (text) colours are typically 30-37. Each number corresponds to a specific colour, and in this case, 32
represents the colour green.Text to be Formatted: Following the control sequence, you include the actual text you want to format with the specified colour and style.
Reset Code:
\e[0m
or \033[0m
: This code is used to reset the text properties to default. It ensures that any formatting changes (such as colour or style) made in the previous control sequence do not affect subsequent text.
echo -e "\033[<FORMAT_OPTION>;<COLOR_CODE>m TEXTS OF THE STRING \033[0m"
echo -e "\033[1;32m This is bold green text \033[0m"