bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

unreliable value of LINENO variable


From: Giacomo Comes
Subject: unreliable value of LINENO variable
Date: Mon, 4 Dec 2023 09:46:45 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

I use often the value of LINEO in order
to know where to look for issues in a script.
Recently I discovered a bug.

Please consider the following 6 line script:
------------------------------------------------
#!/bin/bash

if ((1)); then
       ( : ) ; echo 1 $LINENO
fi
echo 2 $LINENO
------------------------------------------------
if executed it should print:
1 4
2 6
And indeed that's the output if I run it on openSUSE Leap 15.5
(bash 4.4). However if I execute it on openSUSE tumbleweed
(bash 5.2) the  output is:
1 4
2 5
I compiled and tested several version of bash and the conclusion
is that the bug is not there up to bash 4.4.18 and it
shows up in bash-5.0-alpha and later releases.
In order to trigger the bug in your script you need:
1) a compound command executed in a subshell ( : )
2) included in if then fi
The LINENO variable will start to show an incorrect value immediatly after the
fi reserved word.
Example:
------------------------------------------------
#!/bin/bash

if ((1)); then
       ( : ) ; echo 1 $LINENO
       :
       #
       echo 3 $LINENO
fi
echo 2 $LINENO
------------------------------------------------
correct output with 4.4:
1 4
3 7
2 9
wrong output with 5.x:
1 4
3 7
2 5

Please let me know if you need more infotrmation.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]