Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -DRECYCLES_PIDS -DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin' -DSYSLOG_HISTORY -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wno-parentheses -Wno-format-security uname output: Linux gadi-login-06.gadi.nci.org.au 4.18.0-305.19.1.el8.nci.x86_64 #1 SMP Mon Sep 27 03:06:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-redhat-linux-gnu
Bash Version: 4.4 Patch Level: 20 Release Status: release Description: If you have a function, which exports another function, and that exported function contains a generic for loop, the LINENO variable is incorrect for loops in future functions which contain another loop which uses ((..)) notation. Whilst the above system information says bash 4.4.20 20, I have seen it in 3.2.51 and 4.2.46 too. Repeat-By: Below is a sample script to replicate the bug in LINENO. The LINENO variable for the 'i' loop which is printed out by the PS4 is incorrect when that DO_BACKUP function is exported, and the second 'j' loop is uncommented. If you instead uncomment the first 'j' loop, the LINENO variables are correct. If DO_BACKUP does not have a loop inside it, the LINENO variables are all correct. #!/bin/bash export PS4='+L$LINENO + ' setup() { DO_BACKUP() { for d in 1 2 3; do break done } export -f DO_BACKUP } run() { for i in 1; do #for j in 1; do # Uncomment this 'j' loop instead of the next and LINENO is correct #for ((j=1; j<=2; j++)); do # Uncomment this 'j' loop and LINENO is incorrect true done done } set -x setup run ######## Example output with first 'j' loop uncommented: $ bash run.sh +L20 + setup +L9 + export -f DO_BACKUP +L21 + run +L12 + for i in 1 +L13 + for j in 1 +L15 + true Example output with the second 'j' loop uncommented: $ bash run.sh +L20 + setup +L9 + export -f DO_BACKUP +L21 + run +L5 + for i in 1 +L14 + (( j=1 )) +L14 + (( j<=1 )) +L15 + true +L14 + (( j++ )) +L14 + (( j<=1 )) Regards, Tom Coleman