echoコマンドの出力の色を変更する

コマンド

 $ echo -e '\e[VALUE[;VALUE..]mSTRINGS\e[m'

VALUE

Text attributes
0	All attributes off
1	Bold on
4	Underscore (on monochrome display adapter only)
5	Blink on
7	Reverse video on
8	Concealed on
 
Foreground colors
30	Black
31	Red
32	Green
33	Yellow
34	Blue
35	Magenta
36	Cyan
37	White
 
Background colors
40	Black
41	Red
42	Green
43	Yellow
44	Blue
45	Magenta
46	Cyan
47	White

使用例

" fuga fuga " という文字の色を黄色くする
 $ echo -e '\e[33m hoge hoge \e[m'
" hoge hoge " という文字の色を赤くし太字にする
 $ echo -e '\e[1;31m hoge hoge \e[m'

応用

与えられた文字を黄色にして出力するyecho関数を作る

 $ function yecho { echo -e "\e[33m$*\e[m"; }