ANSI Escape

Terminal Colors with Bash

The following is a script I would use for testing. I used it for viewing colors and layout; it’s good for enhancing script feed-back when the script is interactive.

#!/bin/bash
#---------------------------------
#
# Script Name: color_run.sh
# Version: 0.1.1
# Created on: 3/2/2011 Jeff Neuffer Jr
# Updated on: $Id: color_run.sh 105 2013-03-17 14:50:53Z jneuffer $
# Purpose: Display terminal colors
#
#---------------------------------


txtblk='33[0;30m' # Black - Regular
txtred='33[0;31m' # Red
txtgrn='33[0;32m' # Green
txtylw='33[0;33m' # Yellow
txtblu='33[0;34m' # Blue
txtpur='33[0;35m' # Purple
txtcyn='33[0;36m' # Cyan
txtwht='33[0;37m' # White

bldblk='33[1;30m' # Black - Bold
bldred='33[1;31m' # Red
bldgrn='33[1;32m' # Green
bldylw='33[1;33m' # Yellow
bldblu='33[1;34m' # Blue
bldpur='33[1;35m' # Purple
bldcyn='33[1;36m' # Cyan
bldwht='33[1;37m' # White

unkblk='33[4;30m' # Black - Underline
undred='33[4;31m' # Red
undgrn='33[4;32m' # Green
undylw='33[4;33m' # Yellow
undblu='33[4;34m' # Blue
undpur='33[4;35m' # Purple
undcyn='33[4;36m' # Cyan
undwht='33[4;37m' # White

bakblk='33[40m'   # Black - Background
bakred='33[41m'   # Red
badgrn='33[42m'   # Green
bakylw='33[43m'   # Yellow
bakblu='33[44m'   # Blue
bakpur='33[45m'   # Purple
bakcyn='33[46m'   # Cyan
bakwht='33[47m'   # White

txtrst='33[0m'    # Text Reset

echo;echo;
echo -e "33[0;30;47m[         Backup VM Disks           ]33[0m"
echo -e "   33[0;30;47m[ Unregister HDD          ]33[0m"
echo -e "   33[0;30;47m[ Cloning HDD Start       ]33[0m"
echo -e "   33[0;30;47m[ Re-attaching HDD to VM  ]33[0m"
echo; echo;
echo -e "33[0;30;43m[               Disk Usage                   ]33[0m"
df -h

echo; echo;

echo; echo;
exit

Here is what the script produced,
terminal_colors_with_bash_1

There is a better way to view the colors, here is the output from a script from the “Bash-Prompt-HOWTO” [Ref 1]
terminal_colors_with_bash_2

References:
[Ref 1]: http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html