D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] colour in bash print/echo statements?



On Tue, 29 Jun 2004 13:19:05 +0100
Neil Williams <linux@xxxxxxxxxxxxxx> wrote:

Sorry, I should have been clearer - it isn't in a log file, it's coming to the 
screen direct. It's a script that looks for bad servers, so it hangs a lot. I 
can't output to a log file because I'd never know when it's hung.

There are programs that will colourize logs files saved on disk, what I'm 
looking for is a method of getting bash to print in colour WITHOUT going to 
file.


Well, if you have the script in front of you, you could edit the appropriate 
sections and change their output lines to include colouring codes.  I found the 
section on setting your PS1 colours on TLDP's 
http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html to be very helpful with 
regard to the Shell's handling of colours.

As an example:
# Set the font colour to yellow: \033[1;33m
# Print "Hello World" to the screen.
# Re-set the font to default: \033[0m
# Note: the -e and the single-quotes are important.
echo -e '\033[1;33mHello World\033[0m'

Hope this helps.

-- 
Artificial intelligence is no match for nuratal stidutipy.

--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.



Lynx friendly