Skip to content

Close output redirect in Bash

利用&>重定向,不输出任何内容:

echo hello &> /dev/null

关闭正确输出:

echo hello 1> /dev/null

关闭错误输出:

echo hello 2> /dev/null

在Linux上I/O输入输出有三类:标准输入、标准输出、标准错误输出

STDIN     0    默认键盘
STDOUT    1    默认屏幕
STDERR    2    默认屏幕

I/O重定向即改变默认输入/输出的位置

>  >>     重定向标准输出
2>  2>>   重定向错误输出
&>        将标准输出与错误输出重定向至同一文件

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App