shell之trap的使用

temp.sh:

exit 1

test.sh:

trap “echo ‘[ERROR] 執行function: testfunction 失敗’;exit” ERR
sh ./temp.sh

執行./test.sh,腳本會調用trap語句,顯示“[ERROR] 執行function: testfunction 失敗”並退出。

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