I am trying to print a text in the terminal using echo command.
I want to print the text in a red color. How can I do that?
I am trying to print a text in the terminal using echo command.
I want to print the text in a red color. How can I do that?
Nobody noticed the usefulness of the ANSI code 7 reversed video.
It stay readable on any terminal schemes colors, black or white backgrounds, or other fancies palettes, by swapping foreground and background colors.
Example, for a red background that works everywhere:
This is how it looks when changing the terminal built-in schemes:
This is the loop script used for the gif.
See https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
This answer correct, except that the call to colors should not be inside the quotes.
Should do the trick.
This is the color switch
\033[
. See history.Color codes are like
1;32
(Light Green),0;34
(Blue),1;34
(Light Blue), etc.We terminate color sequences with a color switch
\033[
and0m
, the no-color code. Just like opening and closing tabs in a markup language.Simple color
echo
function solution:These codes work on my Ubuntu box:
This prints the letters a b c d all in different colors:
For loop:
I've written swag to achieve just that.
You can just do
Now you can install all the the escape commands as txt files to a given destination via:
Or even easier via:
Which will install the colors to
~/.colors
.Either you use them like this:
Or this way, which I find actually more interesting:
Check it out on asciinema!
Here is the simplest and readable solution. With bashj (https://sourceforge.net/projects/bashj/), you would simply choose one of these lines:
256x256x256
colors are available if you have the color support in your terminal application.