Saturday, December 22, 2007

Colors in BASH


The Numeric Codes for different colors are below:

+--------------------------------------------------+
|color | foreground | background |
+--------------------------------------------------+
|black | 30 | 40 |
|red | 30 | 40 |
|green | 32 | 42 |
|yellow | 33 | 43 |
|blue | 34 | 44 |
|magenta| 35 | 45 |
|cyan | 36 | 46 |
|white | 37 | 47 |
+------------------------------------------------+














Note:
echo -e '\E[COLOR1;COLOR2m THE TEXT.'
tput sgr0 = > Reset text attributes to normal without clear.

The Following BASH code will print all the color combinations:

#!/bin/bash

for i in `seq 30 37`
do
for j in `seq 40 47`
do
echo -e '\E['$i';'$j'm TEXT'
tput sgr0
done
done

No comments:

© Jadu Saikia www.UNIXCL.com