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


Groups > gnu.bash.bug > #15083 > unrolled thread

$LINENO in a bash script using subshells in if statements

Started bycharles.deledalle@gmail.com
First post2019-07-05 15:30 -0700
Last post2019-07-05 15:30 -0700
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#15083 — $LINENO in a bash script using subshells in if statements

Fromcharles.deledalle@gmail.com
Date2019-07-05 15:30 -0700
Subject$LINENO in a bash script using subshells in if statements
Message-ID<mailman.265.1562375954.2688.bug-bash@gnu.org>
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.

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web