【问题标题】:Piping nginx -V to grep doesn't color matches管道 nginx -V 到 grep 的颜色不匹配
【发布时间】:2020-01-17 17:43:40
【问题描述】:

nginx/1.17.3、GNU grep 2.27 和支持 xterm-256color 的终端(Xfce 终端)由于某种原因在其输出中不提供彩色匹配。 我试过这个:

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

但它根本不突出显示文本,只有无意义的白色文本墙,即 nginx 编译选项。 $PS1 是彩色的,所以终端本身并没有坏掉!

【问题讨论】:

  • 我相信你不应该在这个论坛上使用脏话,即使是缩写形式。即使是“地狱”这个词也会更好。

标签: bash grep xterm xfce


【解决方案1】:

你需要重定向stderr

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

在此处了解有关2>&1 的更多信息:In the shell, what does " 2>&1 " mean?

【讨论】:

    猜你喜欢
    • 2011-01-20
    • 2023-01-11
    • 2010-10-12
    • 1970-01-01
    • 2015-03-20
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多