shell之trap的使用

temp.sh:

exit 1

test.sh:

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

【shell之trap的使用】执行./test.sh,脚本会调用trap语句,显示“[ERROR] 执行function: testfunction 失败”并退出。

    推荐阅读