14 command-line bash documentation
我正在运行 Ubuntu 10.10,上面运行 openbox。我今天注意到一个名为 的命令caller,但是没有手册页,它不响应任何输入(或 --help)并且 whereis 找不到它。
知道它是什么吗?
enz*_*tib 18
跑
type caller
Run Code Online (Sandbox Code Playgroud)
你会看到它是一个内置的外壳。跑步
help caller
Run Code Online (Sandbox Code Playgroud)
将显示其功能,在 bash 的手册页中也有报告。简要地
Return the context of the current subroutine call.
ken*_*orb 12
的caller是出现在击3.0版本内置命令(未由POSIX指定)并把它返回任何活性子程序调用的上下文中。请参阅:Bash-Builtins以获得更多阅读。
句法:
caller [FRAMENUMBER]
Run Code Online (Sandbox Code Playgroud)
如果帧号作为非负整数提供,则显示与当前执行调用堆栈中该位置对应的行号、子例程名称和源文件。
在没有任何参数的情况下,调用者显示当前子程序调用的行号和源文件名。
在 Bash Hackers Wiki检查以下简单堆栈跟踪:
#!/bin/bash
die() {
local frame=0
while caller $frame; do
((frame++));
done
echo "$*"
exit 1
}
f1() { die "*** an error occured ***"; }
f2() { f1; }
f3() { f2; }
f3
Run Code Online (Sandbox Code Playgroud)
输出:
12 f1 ./callertest.sh
13 f2 ./callertest.sh
14 f3 ./callertest.sh
16 main ./callertest.sh
*** an error occured ***
Run Code Online (Sandbox Code Playgroud)
这是一个不错的die函数示例,用于跟踪中等复杂脚本中的错误:
{ bash /dev/stdin; } <<<$'f(){ g; }\ng(){ h; }\nh(){ while caller $((n++)); do :; done; }\nf'
Run Code Online (Sandbox Code Playgroud)
对于更复杂的调试,可以使用 Bash 扩展调试功能和许多提供比调用者更多细节的特殊参数(例如
BASH_ARG{C,V})。诸如Bashdb 之类的工具可以帮助使用 Bash 的一些更高级的调试功能。
| 归档时间: |
|
| 查看次数: |
9149 次 |
| 最近记录: |