-   Programming (
-   -   Bash:Printing the line number in bash script (

suryaemlinux 02-04-2011 02:48 PM

Bash:Printing the line number in bash script
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.


ghostdog74 02-04-2011 09:11 PM

you can run your script using set -x or run the script with "bash -x script"

ntubski 02-05-2011 09:59 AM


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 (or ${BASH_LINENO[$i-1]} if referenced within another shell function). The corresponding source file name is ${BASH_SOURCE[$i]}. Use LINENO to obtain the current line number.

All times are GMT -5. The time now is 06:13 AM.