简体   繁体   English

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

[英]What is the difference between “>” and “&>” in bash?

In bash we have 3 stream types:在 bash 中,我们有 3 种流类型:

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

So, while executing some program i can use these streams (eg i can redirect them from console to a file or smth like /dev/null, etc):因此,在执行某些程序时,我可以使用这些流(例如,我可以将它们从控制台重定向到文件或类似 /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

I saw that some people write command &> /dev/null看到有人写command &> /dev/null

What is the difference between > and &> in bash? bash 中>&>什么区别?

what is the difference between ">" and "&>" in bash? bash 中的“>”和“&>”有什么区别?

It's a bashism that redirects both stdout and stderr .这是一种重定向stdoutstderr的bashism。 It can also be achieved with the more portable:它也可以通过更便携的方式来实现:

command > file 2>&1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM