本文的例子部分是引用网络上的一篇文章。
Linux的IO输入输出有三类
Standard Input 代码 0
Standard Output 代码 1
Standard Error 代码 2
举个例子:ls test
.sh test1.sh >success.txt
2>&1
将前面执行结果的标准输出流写入success.txt文件,省略了1,全句为:ls test
.sh test1.sh 1>success.txt 2>&1。
错误输出用2,如2>error.txt。用&1表示类似1,和1绑定到一起,输出到一个文件,用&表示绑定在一起。而“&-”表示关闭。
但注意,
command > file 2>file 与command > file 2>&1