这已经是我第二次想要做这件事了,但是我的谷歌搜索技巧再次让我失望了。
在运行 shell 脚本时(例如 bash 脚本),是否有一个程序/脚本来测试当前 shell 是否支持颜色?
或者,有没有一种方法可以获取终端类型并轻松确定它是否支持颜色?
无论哪种方式,都会很有帮助。
你可以使用tput colors
。
对于我的终端,TERM=xterm-256colors
,输出为[鼓声] 256!这里有其他一些例子:
$ TERM=vt100 tput colors
-1
$ TERM=vt220 tput colors
-1
$ TERM=linux tput colors
8
$ TERM=cons25 tput colors
8
$ TERM=linux tput colors
8
$ TERM=rxvt-unicode tput colors
88
另外,tput -Tvt100 colors
也可以让您指定您感兴趣的终端类型。