Scripts may be used to generate a color escape sequences in the terminal text
Text color is determined by the corresponding color code as described. These include:
重置=0,黑色=30,红色=31,绿色=32,
黄色=33,蓝色=34,洋红=35,青色=36,白色=37。
To print color text, enter the following command:
echo -e "\e[1;31m This is red text \e[0m"
Note: wherein \ e [1; 31m is an escape character string, may be set to the color red, \ e [0m color set back again. 31 only need to replace the desired color code on it.
For a colored background, color codes are commonly used:
重置=0,黑色=40,红色=41,绿色=42,黄色=43,
蓝色=44,洋红=45,青色=46,白色=47。
* To set the background color, then enter the following command:
echo -e "\e[1;42m Green Background \e[0m"
Note: These examples contain a number of escape sequences. Man console_codes can use to view the document.
Examples
[zhangfd@localhost shell]$ cat printf1.sh
#!/bin/bash
## filename:printf.sh
echo -e "\e[1;32m `printf "%-5s %-10s %-6s\n" No Name Mark` \e[0m"
echo -e "\e[1;46m `printf "%-5s %-10s %-s\n" - --- ----
printf "%-5s %-10s %-6.4f\n" 1 Sarath 80.3456
printf "%-5s %-10s %-6.4f\n" 2 James 90.9989
printf "%-5s %-10s %-6.4f\n" 3 Jeff 77.564
printf "%-5s %-10s %-6.4f\n" 4 zhangfd 299999990.33`
\e[0m"
Export