简体   繁体   English

将 nginx -V 管道连接到 grep 与颜色不匹配

[英]Piping nginx -V to grep doesn't color matches

nginx/1.17.3, GNU grep 2.27 and xterm-256color capable terminal (Xfce terminal) for some reason doesn't provide colored matches in its output. nginx/1.17.3、GNU grep 2.27 和支持 xterm-256color 的终端(Xfce 终端)出于某种原因在其输出中不提供彩色匹配。 I've tried this:我试过这个:

  1. nginx -V | nginx -V | grep brotli -o --color=always -C9999 grep brotli -o --color=always -C9999
  2. nginx -V | nginx -V | grep -o --color=always -C9999 brotli grep -o --color=always -C9999 brotli
  3. nginx -V | nginx -V | grep --color=always -C9999 brotli grep --color=always -C9999 brotli
  4. nginx -V | nginx -V | grep brotli --color=always -C9999 grep brotli --color=always -C9999
  5. nginx -V | nginx -V | grep brotli -o --color=always grep brotli -o --color=always
  6. nginx -V | nginx -V | grep -o --color=always brotli grep -o --color=always brotli
  7. nginx -V | nginx -V | grep --color=always brotli grep --color=always brotli
  8. nginx -V | nginx -V | grep brotli --color=always grep brotli --color=always

But it simply doesn't highlight text, only meaningless wall of white text that is nginx compile options.但它根本不突出显示文本,只有毫无意义的白色文本墙,即 nginx 编译选项。 $PS1 is colored, so terminal isn't inherently broken! $PS1 是彩色的,所以终端本身并没有损坏!

You need to redirect stderr您需要重定向stderr

nginx -V 2>&1 | grep --color=always -e 'http'

Learn more about 2>&1 here: In the shell, what does " 2>&1 " mean?在此处了解有关2>&1更多信息: 在 shell 中,“2>&1”是什么意思?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM