Format: echo -e "\ 033 [ text background color ; text color m content you want to display \ 033 [0m"
color code:
[root @ the Test tansk] # CAT Color02. SH # / bin /! bash # font color range: 30 - 37 echo -e " \ 033 [30m black word \ 033 [0m " echo -e " \ 033 [31M in red \ 033 [0m " echo -e " \ 033 [32M green word \ 033 [0m " echo -e " \ 033 [33m yellow word \ 033 [0m " echo -e " \ 033 [34m blue word \ 033 [0m " echo -e " \ 033 [35m purple word \ 033 [0m " echo -e "\ 033 [36m azure word \ 033 [0m" Echo -e " \ 033 [37m white word \ 033 [0m " # word Background color range: 40 - 47 echo -e " \ 033 [40; 37m on black \ 033 [0m " echo -e " \ 033 [ 41; 30m black on red \ 033 [0m " echo -e " \ 033 [42 is; 34m blue characters on a green background \ 033 [0m " echo -e " \ 033 [43 is; 34m blue on a yellow background \ 033 [0m " echo -e " \ 033 [44 is; 30m blue black \ 033 [0m " echo -e " \ 033 [45; 30m purple black bottom \ 033 [0m " echo -e "\ 033 [46; 30m sky blue black \ 033 [0m" Echo -e " \ 033 [47; 34m white with blue letters \ 033 [0m " # Control Option Description # \ 033 [0m turn off all attributes # \ 033 [1M set high brightness # \ 033 [4M underlined echo -e " \ 033 [4; 31m underlined in red \ 033 [0m " # flashes echo -e " \ 033 [5; 34m red blinking \ 033 [0m " # anti shadow echo -e " \ 033 [8M blanking \ 033 [0m " # \ 033 [30m- \ 033 [37m set the foreground color # \ 033 [40m- \ 033 [47M set the background color # \ 033[row nA cursor shift n # \ 033 [nB of n rows down cursor echo -e " \ 4 shift row 033 [4A cursor \ 033 [0m " # \ 033 [nC cursor right row n # \ 033 [nD cursor left row n # \ 033 [Y; xH set the cursor position # \ 033 [2J clear screen # \ 033 [K clears the contents from the cursor to the end of the echo -e " \ 033 [K clears the contents of the cursor to the end \ 033 [0m " # \ 033 [S save cursor position # \ 033 [U restore the cursor position # \ 033 [? 25 | hide the cursor # \ 033 [? 25H display cursor echo-e " \ 033 [? 25L hide the cursor \ 033 [0m " echo -e " \ 033 [? 25H display cursor \ 033 [0m "
effect:
For example the following functions:
#!/bin/bash #设置颜色 function color(){ if [ $1 == "gree" ]; then color01=$( echo -e "\033[32;40m$1\033[0m" ) echo $color01 elif [ $1 == "red" ]; then color02=$( echo -e "\033[31;40m$1 \033[0m" ) echo $color02 else echo -e "\ 033 [44; 37; 5m input error, without this option \ 033 [0m " Fi } Color $ . 1
Achieve results: