获取在bash彩色输出 [英] Get color output in bash
本文介绍了获取在bash彩色输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
编译Linux终端上的一些项目时,我通常会很长的输出包括了大量的信息。通常这些信息是单色的。我不知道是否庆典可以以某种方式修改,所以在所有输出或者在某些特定的产出(比如从Makefile文件等),我可以得到不同的颜色dependeing上,例如:
when compiling some projects on linux terminal, I get usually a long output consisting of a lot of information. Usually this information is MONOCHROME. I wonder if bash can be modified somehow, so in all outputs or in some specific outputs (like from Makefile, etc) I can get different colors dependeing on, for instance:
make[1]: Leaving directory
或
g++ -DHAVE_CONFIG_H -I.
等。
感谢
推荐答案
当然,只要使用Bash函数一样,说这个人:
Sure, just use Bash functions, like, say this one:
make()
{
pathpat="(/[^/]*)+:[0-9]+"
ccred=$(echo -e "\033[0;31m")
ccyellow=$(echo -e "\033[0;33m")
ccend=$(echo -e "\033[0m")
/usr/bin/make "$@" 2>&1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&$ccend%g" -e "/[Ww]arning[: ]/ s%$pathpat%$ccyellow&$ccend%g"
return ${PIPESTATUS[0]}
}
(最初通过突出显示制作警告。)
这篇关于获取在bash彩色输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文