9

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

  • 0(标准输入)
  • 1(标准输出)
  • 2 (标准错误)

因此,在执行某些程序时,我可以使用这些流(例如,我可以将它们从控制台重定向到文件或类似 /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>和in有什么区别?&>

4

1 回答 1

14

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

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

command > file 2>&1
于 2012-08-31T08:30:41.773 回答