Skip to content

Instantly share code, notes, and snippets.

@ebta
Last active May 18, 2023 09:52
Show Gist options
  • Save ebta/82c10ac4c75dcff3eef9376e7bc17ebe to your computer and use it in GitHub Desktop.
Save ebta/82c10ac4c75dcff3eef9376e7bc17ebe to your computer and use it in GitHub Desktop.
Coloring Bash Terminal

Enable nano syntax highlither

find /usr/share/nano/ -iname "*.nanorc" -exec echo include {} \; >> ~/.nanorc

Printing a colored output

A script can use escape sequences to produce colored text on the terminal.

Colors for text are represented by color codes, including, reset = 0, black = 30, red = 31, green = 32, yellow = 33, blue = 34, magenta = 35, cyan = 36, and white = 37.

To print colored text, enter the following command:

echo -e "\e[1;31m This is red text \e[0m"

Here, \e[1;31m is the escape string to set the color to red and \e[0m resets the color back. Replace 31 with the required color code.

For a colored background, reset = 0, black = 40, red = 41, green = 42, yellow = 43, blue = 44, magenta = 45, cyan = 46, and white=47, are the commonly used color codes.

To print a colored background, enter the following command:

echo -e "\e[1;42m ...

ref: https://www.oreilly.com/library/view/linux-shell-scripting/9781785881985/b0ddd805-aa79-441d-b5a7-380c66c7712d.xhtml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment