Exploit-DB updates

Saturday, May 14, 2011

Using colors in bash scripts with ANSI/TV100 codes.

Well, I've made a few posts related to bash scripting so I though I'd make a quick post showing how you can add some color to your scripts. We will be using ANSI, here's a quick example of how to use it;

echo -e "Hey look at \033[1;32;1m this color, we'll make the rest of the script blue \033[0;34;1m"
nmap 127.0.0.1


Make sure you remember the "-e", which enables the interpretation of backslash escapes so it will actually except the ANSI code rather than printing it out like a normal string.
Console Color chart
Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown       0;33     Yellow        1;33
Light Gray  0;37     White         1;37
 
Backgrounds 
40     Black
41       Red
42     Green
43    Yellow
44      Blue
45   Magenta
46      Cyan
47     White

  
You can also add other attributes such as using underlined or bold/bright text by changing the last digit in the code, just before the "m". For example, to use the underline attribute I would do this;


echo -e "Hey look at \033[1;32;1m this color, we'll make the rest of the script blueish \033[0;34;4m"
echo -e "This is underlined\033[0m this is not"
 

 Some Useful Attribute Codes 

0m = Reset all attributes.
1m = Set the "bright" attribute.
2m = Set the "dim" attribute.
4m = Sets the "underline" attribute
5m = Sets the "blink" attribute.
7m = Sets the "reverse" attribute.
8m = Sets the "hidden" attribute.

This is where I'll end this quick example of ANSI/TV100 being used to add color to your bash scripts. This is only a sample of the possibilities these codes create, so don't think it ends here. You can learn more at this site.

No comments:

Post a Comment