我正在写一个相当大的shell脚本。有没有办法从该脚本打印脚本的行号?基本上我想有类似于gcc LINE宏的东西。这将帮助我调试我的脚本。__LINE__等价于Linux shell
由于提前,
Souvik
我正在写一个相当大的shell脚本。有没有办法从该脚本打印脚本的行号?基本上我想有类似于gcc LINE宏的东西。这将帮助我调试我的脚本。__LINE__等价于Linux shell
由于提前,
Souvik
不得不这样做我自己前一段时间,发现这个有用的文章当时:http://aymanh.com/how-debug-bash-scripts#adding-line-numbers-to-tracing-output
从本质上讲,你需要使用$LINENO
拿到脚本当前行。
也许这有助于一点点:
http://www.network-theory.co.uk/docs/bashref/BashVariables.html
BASH_LINENO
An array variable whose members are the line numbers in source files corresponding to each member of FUNCNAME. ${BASH_LINENO[$i]} is the line number in the source file where ${FUNCNAME[$i]} was called. The corresponding source file name is ${BASH_SOURCE[$i]}. Use LINENO to obtain the current line number.
的$LINENO
变量返回在其中使用该变量行。
谢谢大家.. $ LINENO包含行号值。 – Souvik 2010-09-13 10:21:13