簡體   English   中英

bash 中的“>”和“&>”有什么區別?

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

在 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 中>&>什么區別?

bash 中的“>”和“&>”有什么區別?

這是一種重定向stdoutstderr的bashism。 它也可以通過更便攜的方式來實現:

command > file 2>&1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM