[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
$LINENO in a bash script using subshells in if statements
From: |
charles . deledalle |
Subject: |
$LINENO in a bash script using subshells in if statements |
Date: |
Fri, 5 Jul 2019 15:30:20 -0700 (PDT) |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-LQgi2O/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses -Wno-format-security
uname output: Linux denver 5.0.0-16-generic #17-Ubuntu SMP Wed May 15 10:52:21
UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.0
Patch Level: 3
Release Status: release
Description:
Using a subshell environment in an if statement screws up my $LINENO
variable, see minimal reproducible code below.
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.
The problem occurs with Bash 5.0.3. It does not occur with 4.2.3 or
3.2.57. See discussion here:
https://stackoverflow.com/questions/56909685/weird-behavior-of-lineno-in-a-bash-script-using-subshells-in-if-statements
Repeat-By:
Here is the minimal reproducible code
1. #!/bin/bash
2. if true ; then
3. (echo dummy)
4. fi
5. echo "Line no:" $LINENO
Shows "Line no: 4" instead of 5.
Fix:
Problem can be fixed as
1. #!/bin/bash
2. (if true ; then
3. (echo dummy)
4. fi)
5. echo "Line no:" $LINENO
but this is quite a hugly workaround.
- $LINENO in a bash script using subshells in if statements,
charles . deledalle <=