輸出重定向使用案例總結

假設兩個文件 test.sh存在和test1.sh不存在

  • ls test.sh test1.sh 1>svc.txt
    正確輸出重定向到文件svc.txt

  • ls test.sh test1.sh 1>svc.txt 2>err.txt
    正確輸出重定向到文件svc.txt,把錯誤輸出重定向到文件err.txt

  • ls test.sh test1.sh 2>&- 或者 ls test.sh test1.sh 2>/dev/null
    錯誤輸出關閉掉,不輸出錯誤信息

  • ls test.sh test1.sh 1>&- 2>&- 或者 ls test.sh test1.sh 1>/dev/null 2>/dev/null 或者 ls test.sh test1.sh &>/dev/null
    關閉正確輸出錯誤輸出

  • ls test.sh test1.sh >/dev/null 2>&1
    正確輸出關閉,錯誤輸出重定向到正確輸出使用的設備上去

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章