Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15083

$LINENO in a bash script using subshells in if statements

From charles.deledalle@gmail.com
Newsgroups gnu.bash.bug
Subject $LINENO in a bash script using subshells in if statements
Date 2019-07-05 15:30 -0700
Message-ID <mailman.265.1562375954.2688.bug-bash@gnu.org> (permalink)
References <20190705223020.2AF67C61CA9@denver>

Show all headers | View raw


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.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

$LINENO in a bash script using subshells in if statements charles.deledalle@gmail.com - 2019-07-05 15:30 -0700

csiph-web