bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Parsing regression with for loop in case statement


From: nbowler
Subject: Parsing regression with for loop in case statement
Date: Wed, 10 Apr 2024 20:51:12 -0400

Configuration Information [Automatically generated, do not change]:
Machine: powerpc64le
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Linux aion 6.8.1 #26 SMP PREEMPT Fri Mar 15 23:18:26 EDT 2024 
ppc64le POWER9, altivec supported PowerNV C1P9S01 REV 1.02 GNU/Linux
Machine Type: powerpc64le-unknown-linux-gnu

Bash Version: 5.2
Patch Level: 21
Release Status: release

Description:
The POSIX shell grammar specifies that a newline may optionally appear
before the in keyword of a for loop.  Bash does handle this OK in the
following example:

  % cat >test1.sh <<'EOF'
for x
in x
do
echo $x
done
EOF
  % bash test1.sh
  x

However, if the exact same loop is placed within the body of a case
statement, current versions of bash exit with a syntax error:

  % cat >test2.sh <<'EOF'
case x in x)
for x
in x
do
echo $x
done
esac
EOF
  % bash --version
  GNU bash, version 5.2.21(1)-release
  [...]
  % bash test2.sh
  test2.sh: line 4: syntax error near unexpected token `do' 
  test2.sh: line 4: `do'

Enabling POSIX compatibility mode does not appear to have any effect.

This failure seems to be a regression introduced in bash-5.0.
Prior versions of bash (up to 4.18) work as expected:

  % bash --version
  GNU bash, version 4.4.18(1)-release
  [...]
  % bash test2.sh
  x

No other shell I've tried has any problem with this syntax.

Let me know if you need any more info!

Thanks,
  Nick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]