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
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
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.
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.
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.
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'
This should be easier, like it is in powershell:
Write-Error "Access denied."
© 2022 - 2024 — McMap. All rights reserved.