/home

Icon

Informations, tips and technics.

Give your bash scripts some colors

I am pretty sure that every guy that everyone that manage Linux or Unix systems have to deal with bash to create some scripts.

I am currently create one that retrieve some informations on different NIX platforms, like Suns Solaris and Unix.

The goal of this post is not to explain you how to deal with bash but to add some fun to your bash scripts. Adding colors to a scripts could be cool when you have to display important messages, errors or information. Adding colors to those messages make the user more aware of what’s happening and add some eye candy to you script.

We use the echo command with the -e parameter. Here is a small example :

ESC_SEQ=\x1b[
COL_RESET=$ESC_SEQ39;49;00m
COL_RED=$ESC_SEQ31;01m
COL_GREEN=$ESC_SEQ32;01m
COL_YELLOW=$ESC_SEQ33;01m
COL_BLUE=$ESC_SEQ34;01m
COL_MAGENTA=$ESC_SEQ35;01m
COL_CYAN=$ESC_SEQ36;01m

echo -e $COL_BLUEINFO: $COL_RESETThis is an info message
echo -e $COL_REDAn error has occurred$COL_RESET

ref : http://www.bioinspired.com/users/ajg112/software/bashTips.shtml

Advertisements

Filed under: Bash, , ,

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: