欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
linux腳本之>/dev/null 2>&1,以及2>1 VS 2>&1
[打印本頁]
作者:
51黑tt
時(shí)間:
2016-3-6 15:19
標(biāo)題:
linux腳本之>/dev/null 2>&1,以及2>1 VS 2>&1
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)行下面測試。
# 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
#
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1