基本上,假设我有一个像这样的命令grep
它输出带有类似标志的颜色编码结果-r
。如果我将此命令包装在 shell 脚本中,则在运行该脚本时,输出将不会具有相同的颜色编码效果。
有没有其他方法可以使 shell 脚本以相同的颜色编码吐出结果(在终端上),而无需使用tput
或者手动颜色编码?
强制颜色输出grep
:
grep --color=always
From man grep
:
--color[=WHEN], --colour[=WHEN]
Surround the matched (non-empty) strings,
matching lines, context lines, file names, line
numbers, byte offsets, and separators (for fields
and groups of context lines) with escape
sequences to display them in color on the
terminal. The colors are defined by the
environment variable GREP_COLORS. The deprecated
environment variable GREP_COLOR is still
supported, but its setting does not have
priority. WHEN is never, always, or auto.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)