I am attempting to get line numbers displayed on the console while debugging a sourced Bash script.
I use the following code to enable debugging:
<code>set -x
export PS4="Line $LINENO"
</code>
<code>set -x
export PS4="Line $LINENO"
</code>
set -x
export PS4="Line $LINENO"
but I am getting the following output:
<code>set -x
export 'PS4=Line 26'
PS4='Line 26'
LLine 26sourced=0
LLine 26'[' -n '' ']'
LLine 26'[' -n '' ']'
LLine 26'[' -n '5.1.16(1)-release' ']'
LLine 26return 0
LLine 26sourced=1
LLine 26'[' '!' -n 1 ']'
LLine 26'[' -n UM ']'
LLLine 26currentVe
LLLine 26'[' -x /usr/lib/command-not-found ']'
LLLine 26/usr/lib/command-not-found -- currentVe
currentVe: command not found
LLLine 26return 127
LLine 26'[' -n ']'
LLine 26'[' '' '!=' UM ']'
LLine 26echo 'Trying to use Virtual environment UM while is still active'
Trying to use Virtual environment UM while is still active
LLine 26return 2
</code>
<code>set -x
export 'PS4=Line 26'
PS4='Line 26'
LLine 26sourced=0
LLine 26'[' -n '' ']'
LLine 26'[' -n '' ']'
LLine 26'[' -n '5.1.16(1)-release' ']'
LLine 26return 0
LLine 26sourced=1
LLine 26'[' '!' -n 1 ']'
LLine 26'[' -n UM ']'
LLLine 26currentVe
LLLine 26'[' -x /usr/lib/command-not-found ']'
LLLine 26/usr/lib/command-not-found -- currentVe
currentVe: command not found
LLLine 26return 127
LLine 26'[' -n ']'
LLine 26'[' '' '!=' UM ']'
LLine 26echo 'Trying to use Virtual environment UM while is still active'
Trying to use Virtual environment UM while is still active
LLine 26return 2
</code>
set -x
export 'PS4=Line 26'
PS4='Line 26'
LLine 26sourced=0
LLine 26'[' -n '' ']'
LLine 26'[' -n '' ']'
LLine 26'[' -n '5.1.16(1)-release' ']'
LLine 26return 0
LLine 26sourced=1
LLine 26'[' '!' -n 1 ']'
LLine 26'[' -n UM ']'
LLLine 26currentVe
LLLine 26'[' -x /usr/lib/command-not-found ']'
LLLine 26/usr/lib/command-not-found -- currentVe
currentVe: command not found
LLLine 26return 127
LLine 26'[' -n ']'
LLine 26'[' '' '!=' UM ']'
LLine 26echo 'Trying to use Virtual environment UM while is still active'
Trying to use Virtual environment UM while is still active
LLine 26return 2
The number 26 is the line number of the Bash statement where PS4 is set.
This technique used to work but I now can find no way of making it useful. I have tried firing up a new Bash shell and even rebooting my computer without any sucess. Any ideas on what I should do. I am trying to debug a problem where the line numbers could be invaluable.