开发者

__LINE__ equivalent for Linux shell

I am writing a considerably huge shell script. Is there any way to print the line number of the script from that script? Basically I want to have something similar to gcc LINE macro. This will help me to debug my script.

Thanks in advance,

开发者_JAVA百科

Souvik


Maybe this helps a little bit:

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. 


Had to do it myself a while ago and found this useful article back then: http://aymanh.com/how-debug-bash-scripts#adding-line-numbers-to-tracing-output

Essentially you need to use $LINENO to get the current line in the script.


The $LINENO variable returns the line in which that variable is used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜