shell脚本中的`set -o errtrace`会执行什么?

set -o errtrace 

shell脚本中的上述语句将执行什么? 特别是-o命令?

Solutions Collecting From Web of "shell脚本中的`set -o errtrace`会执行什么?"

从手册:

 errtrace Same as -E. -E If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a sub‐ shell environment. The ERR trap is normally not inher‐ ited in such cases. 

当启用errtrace时,当在函数或子shell中发生错误(一个返回非零代码的命令)时,也会触发ERR陷阱。 换句话说,我们可以说,除非启用了errtrace否则函数或子shell的上下文不会继承ERR陷阱。

 #!/bin/bash set -o errtrace function x { echo x start false echo x end } function y { echo y start false echo y end } trap 'echo "Error occurred on $FUNCNAME."' ERR x y false true 

输出:

 x start Error occurred on x. x end y start Error occurred on y. y end Error occurred on . 

errtrace未启用时:

 x start x end y start y end Error occurred on .