ERR背后的实际信号是什么 [英] What is the actual signal behind ERR
问题描述
我已经在多个地方(包括SO)阅读到 -e
被认为是不良形式",并且在出现任何错误时退出脚本都不可靠.处理错误的更好方法似乎是使用 trap
,例如:
陷阱回显错误;退出1;"呃
我似乎无法在手册页中找到 ERR
的实际信号是什么?我假设它是 SIGQUIT
,但我不确定.
man 7信号
只有您期望的正常信号 SIGTERM SIGQUIT SIGINT
等.
man陷阱
具有对 ERR
信号的引用,但似乎没有对其进行定义.
ex:"在ERR上的陷阱(如果已设置)在外壳程序退出之前执行.
"
man bash
与 man trap
相似,因为它引用了 ERR
,但未根据我所见对其进行定义.
快捷方式 ERR
背后的实际信号是什么?(在正常的信号中,如 man 7 signal
所示).
尽管我意识到它们会产生相同的结果(从脚本中的命令捕获任何错误,然后扔给处理程序),但我更希望捕获实际的信号名称而不是简写形式.
没有与 trap
信号规范 ERR
相对应的信号.
ERR
是 bash
在内部实现的信号规范之一.[注1]如果启用了 trap ERR
,则bash将在与启用了 set -e
时退出的情况完全相同的情况下调用相应的处理程序.(因此,它比 set -e
不再可靠",但是它更加灵活.)
与任何信号都不对应的其他特殊 trap
名称是 EXIT
, DEBUG
和 RETURN
./p>
帮助陷阱
将解释这些信号规范的含义.
注释:
- 实际上,所有信号规范都是由
bash
实现的,但是大多数都是由bash
捕获信号然后执行信号处理程序实现的.特殊的只是涉及执行信号处理程序.
I've read in several places (including SO) that -e
is considered "poor form" and is unreliable for exiting a script on any error. A better way to handle errors seems to be using trap
, as such:
trap "echo there was an error; exit 1;" ERR
I can't seem to locate in the man pages what signal ERR
is actually? I'm assuming it's SIGQUIT
but I can't find for sure.
man 7 signal
only has the normal signals you would expect SIGTERM SIGQUIT SIGINT
, etc.
man trap
has references to ERR
signal, but doesn't seem to define it.
ex: "A trap on ERR, if set, is executed before the shell exits.
"
man bash
is similar to man trap
in that is makes references to ERR
but doesn't define it from what I've seen.
What is the actual signal behind the shortcut ERR
? (in normal signals as seen in man 7 signal
).
I'd prefer to trap the actual signal name instead of the shorthand version, although I realize they would produce the same results (catching any error from a command in a script then throwing to the handler).
There is no signal corresponding to the trap
signal specification ERR
.
ERR
is one of the signal specifications implemented internally by bash
. [Note 1] If trap ERR
is enabled, then bash will invoke the corresponding handler in exactly the same cases as it would have exited had set -e
been enabled. (Consequently, it is no more "reliable" then set -e
but it is a lot more flexible.)
Other special trap
names which do not correspond to any signal are EXIT
, DEBUG
and RETURN
.
help trap
will explain the meaning of these signal specifications.
Notes:
- Actually, all of the signal specifications are implemented by
bash
, but most of them are implemented bybash
trapping the signal and then executing the signal handler. The special ones just involve executing the signal handler.
这篇关于ERR背后的实际信号是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!