本文介绍了什么`在shell脚本设置-o errtrace`将执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 设置-o errtrace

在什么shell脚本上述声明将执行?
具体来说 -o 命令?


解决方案

这本手册:

When errtrace is enabled, the ERR trap is also triggered when the error (a command returning a nonzero code) occurs inside a function or a subshell. We can probably tell is in other words that the context of a function or a subshell does not inherit the ERR trap unless the errtrace is enabled.

#!/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

Output:

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

When errtrace is not enabled:

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

这篇关于什么`在shell脚本设置-o errtrace`将执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 16:25