仅Bash打印stderr,而不是stdout [英] Bash print stderr only, not stdout

查看:62
本文介绍了仅Bash打印stderr,而不是stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想整理一个文件,并打印stderr(错误消息),但不打印stdout(说文件没问题).

I want to lint a file, and print the stderr (error message), but do not print the stdout (saying the file is OK).

php -l "foo/bar.php"

  • 如果没有错误,它将向标准输出显示"No errors"消息.
  • 如果有错误,它将向stderr打印一条详细消息.我只想要这个.
  • 我认为使用>& 会有些神奇,但是我从来不了解它们是如何工作的.

    I figure it will be some magic with >&, but I never understood how those work.

    我要消耗掉所有stdout,保留stderr.

    What I want is to consume all stdout, keep stderr.

    (对不起,这是双重的,但我还没有找到与此完全相关的任何问题)

    (Sorry if this is dulicate, but I haven't found any question exactly about this)

    推荐答案

    只需将标准输出发送为null:

    Just send the stdout to null:

    cmd > /dev/null
    

    这保留了stderr,但抑制了stdout.

    This retains stderr, but suppresses stdout.

    这篇关于仅Bash打印stderr,而不是stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆