How to display build errors in red
Asked Answered
B

4

5

I think I have done this before: when I do a command line 'make' I would like my output color coded - you know yellow for warnings and red for errors.

Any idea how I can do this in the BASH shell?

thanks! Jas

Bellwether answered 17/1, 2011 at 20:48 Comment(0)
G
6

There is a program called colormake that's a wrapper around the real make that does exactly what you want. You might want to check it out and give it a try; from experience it works quite well.

Ginkgo answered 17/1, 2011 at 20:58 Comment(0)
K
7

May I suggest the following method for colors in Bash, it makes the code much more readable and alot harder for you to miss an escape or two.

Put the following in your ~/.bashrc

BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
LIME_YELLOW=$(tput setaf 190)
YELLOW=$(tput setaf 3)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)

So your example would simply be:

echo "Error Code: ${RED}1234${NORMAL}"

If you have a 256-color terminal, you can experiment with other numerical values to tput setaf all the way up to 255.

Kickstand answered 17/1, 2011 at 20:52 Comment(0)
G
6

There is a program called colormake that's a wrapper around the real make that does exactly what you want. You might want to check it out and give it a try; from experience it works quite well.

Ginkgo answered 17/1, 2011 at 20:58 Comment(0)
N
5

If your terminal supports ANSI escape sequences (most terminal emulators do), it's the way to go.

For example to display a word in red :

echo -e '\033[31m RED \033[0m Normal'
Nicholle answered 17/1, 2011 at 20:50 Comment(0)
T
-2

This should be easier, like it is in powershell:

Write-Error "Access denied."
Taxidermy answered 13/9, 2022 at 9:10 Comment(1)
down voted for non bash commandRaffinate

© 2022 - 2024 — McMap. All rights reserved.