linux shell下常用輸入輸出操作符是:
- 標準輸入standard input 0
- 正確輸出standard output 1
- 錯誤輸出:error output 2
默認是1。
有如下test.sh
#!/bin/bash
date
l3
執行腳本
./test.sh 1> suc.log 2>err.log 2>&2
運行結果:
suc.log
Tue May 17 12:31:14 CST 2016
err.log
./test.sh: line 3: l3: command not found
說明:
1>把標準輸出輸出到suc.log
2>把錯誤輸出輸出到err.log
2>&2的意思是:把錯誤輸出輸出到錯誤輸出的文件(err.log),注意不能有2>>&2這種寫法
一般把正確和錯誤都輸出到同一個文件:
./test.sh &>> test.log
等價
./test.sh >> test.log 2>&1