bash字体颜色修改【转】


You can use these ANSI escape codes:



Black 0;30 Dark Gray 1;30
Red 0;31 Light Red 1;31
Green 0;32 Light Green 1;32
Brown/Orange 0;33 Yellow 1;33
Blue 0;34 Light Blue 1;34
Purple 0;35 Light Purple 1;35
Cyan 0;36 Light Cyan 1;36
Light Gray 0;37 White 1;37</pre> And then use them like this in your script: <pre># .———- constant part!
# vvvv vvvv– the code from above
RED=’\033[0;31m’
NC=’\033[0m’ # No Color
printf “I ${RED}love${NC} Stack Overflow\n”</pre> which printslovein red. From @james-lim's comment, if you are using theechocommand, be sure to use the -e flag to allow backslash escapes. <pre># Continued from above example
echo -e “I ${RED}love${NC} Stack Overflow”


(don’t add "\n" when using echo unless you want to add additional empty line)

转载请注明来源链接 http://just4fun.im/2017/04/03/bash-e5-ad-97-e4-bd-93-e9-a2-9c-e8-89-b2-e4-bf-ae-e6-94-b9-e3-80-90-e8-bd-ac-e3-80-91/ 尊重知识,谢谢:)