【问题标题】:Syntax of redirection the stderr and stdout to dev/null将 stderr 和 stdout 重定向到 dev/null 的语法
【发布时间】:2018-02-25 14:24:01
【问题描述】:

我想将 stderr 和 stdout 重定向到 dev/null。 哪种是正确的重定向方式,这些选项之间有区别吗? 我在网上看到过两种语法:

  1. command &>/dev/null(无空格)

  2. command &> /dev/null(带空格)

提前致谢!

【问题讨论】:

标签: bash syntax stdout stderr io-redirection


【解决方案1】:

Bash 允许在 redirection 运算符周围使用空格,因此这两种形式都有效。

也就是说,您不能在更复杂的重定向运算符的部分之间使用空格,例如:

command 2> /dev/null   # ok
command 2 > /dev/null  # wrong, the operator is '2>'
command 2> &1          # wrong, the operator is '2>&1'

【讨论】:

    猜你喜欢
    • 2011-05-14
    • 2012-01-23
    • 2019-10-11
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 2012-08-07
    • 2017-11-30
    • 2022-01-18
    相关资源
    最近更新 更多