Re: echo test >& "quote'test"
On 4/8/24 9:37 PM, squeaky wrote: Bash Version: 5.2 Patch Level: 21 Release Status: release Description: Running echo test >& "quote'test" should create the file "quote'test", but it creates "quotetest" instead. Repeat-By: echo test >& "quote'test" Thanks for the report. This is specific to this form of redirection. The issue is that the WORD following the >& is expanded multiple times, since it has to be expanded once to determine whether it's a number, filename, `-', or empty. Once it's expanded, and known to be a filename, it shouldn't be expanded again. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Parsing regression with for loop in case statement
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
Re: Parsing regression with for loop in case statement
I can confirm that this changed between 4.4.23(49)-release and 5.0.0(1)-beta, which coincides with the parser being largely rewritten. On Thu, 11 Apr 2024 at 12:51, wrote: > The POSIX shell grammar specifies that a newline may optionally appear > before the in keyword of a for loop. I don't see that at §2.9.4 "The for Loop" ( https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_03) and I've never seen it in the wild. But ... oh look, it's mentioned in §2.10.2 ( https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02 ). I wonder when that was added, and why? -Martin
Re: Parsing regression with for loop in case statement
On Wed, Apr 10, 2024, at 11:07 PM, Martin D Kealey wrote: > But ... oh look, it's mentioned in §2.10.2 ( > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02 > ). > > I wonder when that was added, and why? It's been there since at least POSIX.2-1992 [1]. At a glance, it looks like the Bourne shell accepted LFs before "in" from the very beginning [2]. (The Solaris 10 shell definitely does accept them.) [1]: https://archive.org/details/ieeestandardforiinst [2]: https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh/cmd.c -- vq
Re: Parsing regression with for loop in case statement
On Thu, 11 Apr 2024 15:07:14 +1200 Martin D Kealey wrote: > I can confirm that this changed between 4.4.23(49)-release and > 5.0.0(1)-beta, which coincides with the parser being largely rewritten. > > On Thu, 11 Apr 2024 at 12:51, wrote: > > > The POSIX shell grammar specifies that a newline may optionally appear > > before the in keyword of a for loop. > > > I don't see that at §2.9.4 "The for Loop" ( > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04_03) > and I've never seen it in the wild. > > But ... oh look, it's mentioned in §2.10.2 ( > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02 > ). > > I wonder when that was added, and why? I checked as far back as Issue 4 Version 2 (1994), which supports it. Specifically, it specifies the following two forms: - for name linebreak do_group - for name linebreak in wordlist sequential_sep do_group Issue 6 additionally specifies the following form: - for name linebreak in sequential_sep do_group As a consequence of https://austingroupbugs.net/view.php?id=581, Issue 7 additionally specifies the following form: - for name sequential_sep do_group Note that "linebreak" implies either a "newline_list" or nothing at all. With that in mind, here are some examples. for var do :; done for var in 1; do :; done for var in; do :; done for var; do :; done -- Kerin Millar