【发布时间】:2016-05-02 13:55:39
【问题描述】:
如何在"$0" 和"${BASH_SOURCE[0]}" 之间进行选择
来自GNU 的描述对我没有多大帮助。
BASH_SOURCE
An array variable whose members are the source filenames where the
corresponding shell function names in the FUNCNAME array variable are
defined. The shell function ${FUNCNAME[$i]} is defined in the file
${BASH_SOURCE[$i]} and called from ${BASH_SOURCE[$i+1]}
【问题讨论】:
-
BASH_SOURCE在 bash-3.0-alpha 中添加。根据您的测试制度,您可能没有它。我发现它在早期的 Solaris 和 OS X 上都丢失了。另请参阅 U&L.SE 上的return: can only `return' from a function or sourced script。 -
还有其他人认为
An array variable whose members are the source filenames where the corresponding shell function names in the FUNCNAME array variable are defined. The shell function ${FUNCNAME[$i]} is defined in the file ${BASH_SOURCE[$i]} and called from ${BASH_SOURCE[$i+1]}完全是胡言乱语吗?我不知道这意味着什么......如果有人解释一下文档/手册页实际上想说什么,那就太好了。 -
当我意识到文档描述的是构建堆栈跟踪所需的点点滴滴时,这些文档更有意义。 Bash 本身没有堆栈跟踪库(我可以找到)。相反,我不得不使用 FUNCNAME 和 BASH_SOURCE 来构建我自己的......
标签: bash