且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

set -e 在 bash 脚本中是什么意思?

更新时间:2022-06-18 04:29:56

来自 help set :

  -e  Exit immediately if a command exits with a non-zero status.

但有些人认为这是不好的做法(bash FAQ 和 irc freenode #bash FAQ 作者).推荐使用:

But it's considered bad practice by some (bash FAQ and irc freenode #bash FAQ authors). It's recommended to use:

trap 'do_something' ERR

在发生错误时运行do_something函数.

to run do_something function when errors occur.

参见 http://mywiki.wooledge.org/BashFAQ/105