title: Weird behavior of $LINENO in a bash script using subshells in if statements
body: <p>Using a subshell environment in an if statement screws up my $LINENO variable. Here is a minimal reproducible code:</p>
  
  <pre><code>1. #!/bin/bash
  2. if true ; then
  3.     (echo dummy)
  4. fi
  5. echo "Line no:" $LINENO
  </code></pre>
  
  <p>It shows "Line no: 4" instead of 5.
  Is that a normal behavior? I could not find any explanations online.
  The problem occurs only if the condition is true (meaning the subshell is executed). Same problem occurs if the subshell is in a while/for loop iterating at least once.</p>
  
  <p>Surprisingly the three pieces of code below work as expected:</p>
  
  <p><strong>a) no if-then-fi</strong></p>
  
  <pre><code>1. #!/bin/bash
  2. (echo dummy)
  3. echo "Line no:" $LINENO
  </code></pre>
  
  <p>shows 3 as expected.</p>
  
  <p><strong>b) no subshell</strong></p>
  
  <pre><code>1. #!/bin/bash
  2. if true ; then
  3.     echo dummy
  4. fi
  5. echo "Line no:" $LINENO
  </code></pre>
  
  <p>shows 5 as expected.</p>
  
  <p><strong>c) nested subshells</strong></p>
  
  <pre><code>1. #!/bin/bash
  2. (if true ; then
  3.     (echo dummy)
  4. fi)
  5. echo "Line no:" $LINENO
  </code></pre>
  
  <p>shows 5 as expected.</p>