【问题标题】:What is the difference between ">" and "&>" in bash?bash中的“>”和“&>”有什么区别?
【发布时间】:2012-08-26 01:09:24
【问题描述】:

在 bash 中,我们有 3 种流类型:

  • 0(标准输入)
  • 1(标准输出)
  • 2 (STDERR)

因此,在执行某些程序时,我可以使用这些流(例如,我可以将它们从控制台重定向到文件或类似 /dev/null 等的文件):

# only errors from STDERR will be shown, STDOUT will be moved to /dev/null
command > /dev/null
# only STDOUT will be shown, STDERR will be moved to /dev/null
command 2> /dev/null

我看到有些人写 command &> /dev/null

>&> 在 bash 中有什么区别?

【问题讨论】:

    标签: linux bash console


    【解决方案1】:

    bash 中的“>”和“&>”有什么区别?

    这是一个重定向 stdoutstderr 的 bashism。也可以通过更便携的方式来实现:

    command > file 2>&1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 2016-03-20
      • 2011-03-26
      • 2015-07-22
      • 1970-01-01
      相关资源
      最近更新 更多