|
1. 標(biāo)準(zhǔn)輸入stdin文件描述符為0,標(biāo)準(zhǔn)輸出stdout文件描述符為1,標(biāo)準(zhǔn)錯(cuò)誤stderr文件描述符為2
2. /dev/null 空設(shè)備,相當(dāng)于垃圾桶
3. 重定向符號(hào):>
3. 2>1 與 2>&1 的區(qū)別
2>1, 把標(biāo)準(zhǔn)錯(cuò)誤stderr重定向到文件1中
2>&1,把標(biāo)準(zhǔn)錯(cuò)誤stderr重定向到標(biāo)準(zhǔn)輸出stdout
4. 舉例:
假設(shè)有腳本test.sh,內(nèi)容如下,t是一個(gè)不存在的命令,執(zhí)行腳本進(jìn)行下面測(cè)試。
# cat test.sh
t
date
標(biāo)準(zhǔn)輸出重定向到log,錯(cuò)誤信息輸出到終端上,如下:
# ./test.sh > log
./test.sh: line 1: t: command not found
# cat log
Thu Oct 23 22:53:02 CST 2008
刪除log文件,重新執(zhí)行,這次是把標(biāo)準(zhǔn)輸出定向到log,錯(cuò)誤信息定向到文件1
# ./test.sh > log 2>1
#
# cat log
Thu Oct 23 22:56:20 CST 2008
# cat 1
./test.sh: line 1: t: command not found
#
把標(biāo)準(zhǔn)輸出重定向到log文件,把標(biāo)準(zhǔn)錯(cuò)誤重定向到標(biāo)準(zhǔn)輸出
# ./test.sh > log 2>&1
#
# cat log
./test.sh: line 1: t: command not found
Thu Oct 23 22:58:54 CST 2008
#
把錯(cuò)誤信息重定向到空設(shè)備
# ./test.sh 2>/dev/null
Thu Oct 23 23:01:07 CST 2008
#
把標(biāo)準(zhǔn)輸出重定向到空設(shè)備
# ./test.sh >/dev/null
./test.sh: line 1: t: command not found
把標(biāo)準(zhǔn)輸出和標(biāo)準(zhǔn)錯(cuò)誤全重定向到空設(shè)備
#./test.sh >/dev/null 2>&1
#
|
|