Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get color output in bash

Tags:

bash

when compiling some projects on linux terminal, I get usually a long output consisting of a lot of information. Usually this information is MONOCHROME. I wonder if bash can be modified somehow, so in all outputs or in some specific outputs (like from Makefile, etc) I can get different colors dependeing on, for instance:

make[1]: Leaving directory 

or

g++ -DHAVE_CONFIG_H     -I. 

etc.

Thanks

like image 819
Open the way Avatar asked Mar 13 '10 10:03

Open the way


People also ask

How do I print text in color in bash?

For example, if you wanted to print green text, you could do the following: #!/bin/bash # Set the color variable green='\033[0;32m' # Clear the color after that clear='\033[0m' printf "The script was executed ${green}successfully${clear}!"


1 Answers

I found that in bash tput setf doesn't work. I found this commands for bash that are working well

handy tput commands

tput bold - Bold effect
tput rev - Display inverse colors
tput sgr0 - Reset everything
tput setaf {CODE}- Set foreground color, see color {CODE} below
tput setab {CODE}- Set background color, see color {CODE} below
Colors {code} code for tput command

Color {code}    Color
0    Black
1    Red
2    Green
3    Yellow
4    Blue
5    Magenta
6    Cyan
7    White
like image 54
Fabio Avatar answered Oct 11 '22 14:10

Fabio