shell之trap的使用

来源:互联网 发布:达洛夫事件知乎 编辑:程序博客网 时间:2024/06/05 04:38

temp.sh:

exit 1

test.sh:

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

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

0 0
原创粉丝点击