#!/bin/bash # # dragging UNIX into the 21st century. # colors in the bash shell.. # # note: this script has no actual "use", it's just a demo # # ;o) # (or # clear # 0 : black # 1 : red # 2 : green # 3 : yellow # 4 : blue # 5 : magenta # 6 : cyan # 7 : grey # 8 : white # by the way, if you want your *first* line to be indented, do a blank before it. echo -e " \033[1;31;7;5m\033[0m" # a quirk of bash, I guess. echo -e " \033[1;32;7;5minstalling such-and-such program..\033[0m" # anyways, back to the bash colors.. # you can enter escape character control codes directly, like this.. echo "Oh my! I am bold yellow!" echo # I used to use this method exclusively, but they tend to tricky to edit # in certain text editors. (the caret gets shifted out of line) # fortunately, you can also enter bash colors like this.. echo -e '\033[1mThis is BOLD text..\033[0m' # using the "-e" switch to tell bash to translate any escape characters that follow. # "\033[" represents the beginning of an escape sequence # (on most platforms, you can also use "\E" or "\e") # "[1" switches on the bold attribute # "[0" switches it off again # "m" terminates each escape sequence # plain colours.. echo echo -e '\033[30mThis is black [38].\033[0m'; echo -e '\033[31mThis is red [31]\033[0m'; echo -e '\033[32mThis is green [32]\033[0m'; echo -e '\033[33mThis is yellow [33]\033[0m'; echo -e '\033[34mThis is blue [34]\033[0m'; echo -e '\033[35mThis is magenta [35]\033[0m'; echo -e '\033[36mThis is cyan [36]\033[0m'; echo -e '\033[37mThis is grey [37]\033[0m'; echo -e "\033[037mRegular White [037]\033[0m" #hmm echo -e "\033[137mRegular White [137]\033[0m" #regular grey text echo -e "\033[038mRegular White [038]\033[0m" #interesting, huh echo # it doesn't matter what style of quotes you use, they both work. # bold.. echo echo -e '\033[1mThis is BOLD text..\033[0m' echo -e '\033[1;31mThis is bold red [31].\033[0m'; echo -e '\033[1;32mThis is bold green [32].\033[0m'; echo -e '\E[01;33mThis is bold yellow [33].\033[0m'; echo -e '\E[1;34mThis is bold blue [34].\033[0m'; echo -e '\E[1;35mThis is bold magenta [35].\033[0m'; echo -e '\e[1;36mThis is bold cyan [36].\033[0m'; echo -e '\e[1;37mThis is bold grey [37] (same as regular bold text).\033[0m'; echo -e '\e[1;30mThis is bold black [30].\033[0m'; echo echo -en '\033[1;31m\033[1mBold Red, \033[0m' # note "-n" to disable the line-break echo -en '\033[1;32m\033[1mGreen, \033[0m' echo -en '\033[1;34m\033[1mand Blue \033[0m' echo # change the backgrounds.. # example.. #echo -e "\E[color1;color2mtext.\033[0m" # "\E[" begins the escape sequence. (or "\033[", or "\e") # "color1" and "color2" are the foreground and a background colors. # The order of the sequence is irrelevant, since the number ranges don't overlap. # background colour is forty-something, and foreground text colour is thirty-something. # "m" terminates each escape sequence, as usual. echo echo -e "\033[37;44mRegular White [37] on Blue background [44]\033[0m" echo -e "\E[37;41m\033[1mBold White [37] on Red background [41]\033[0m" echo -e "\033[31;44m\033[1mBold Red [33] on Blue background [44]\033[0m" echo -e "\E[35;46m\033[1mmagenta [35] on cyan background [46]\033[0m" # for bolding the background use a "5".. echo -e "\033[31;5;44m\033[1mBold Red [33] on BOLD Blue background [44]\033[0m" echo -e "\033[35;5;43m\033[1mBold Magenta [33] on BOLD yellow background [44]\033[0m" echo # a few other bits and pieces.. # a "4" will underline the text.. echo -e "\033[4m Underlined Text \033[0m" echo # a "7" will invert the text.. echo -e "\033[7m Underlined Text (inverted)\033[0m" echo -e "\033[4;45m Underlined Text on Magenta Background \033[0m" echo -e "\033[1;33;5;45m Underlined Yellow Bold Text on Bold Magenta Background *phew* ;o)\033[0m" echo -e "\033[7;36;45m more interesting effects! \033[0m" echo # reset all bash colours.. tput sgr0 # if you don't do this (and you might not want to) the text which # follows will retain the color, ie. your command prompt. # all's well that ends well. exit 0