bug-bash
[Top][All Lists]
Advanced

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

[bug] Command substitutions within C-style for loops. Semicolon causes e


From: Dan Douglas
Subject: [bug] Command substitutions within C-style for loops. Semicolon causes error.
Date: Sat, 29 Oct 2011 00:21:12 -0500

It seems the Bash parser can't distinguish between the semicolon as a
command separator list operator, and the arithmetic context delimiter of
the C-style for loop. I realize this construct isn't particularly useful.
ksh93 and zsh handle it as expected, but in Bash it causes a syntax error
on my system.

Sorry I couldn't think of an example that isn't completely pointless:
$ ( ksh -c 'for (( i = j = k = 1; i % 9 || (j *= -1, $( ((i%9)) || printf "
" >&2; echo 0), k++ <= 10); i += j )); do printf "$i"; done' )
12345678 987654321 012345678 987654321 012345678 987654321 012345678
987654321 012345678 987654321 012345678

$ ( for (( i = j = k = 1; i % 9 || (j *= -1, $( ((i%9)) || printf " " >&2;
echo 0), k++ <= 10); i += j )); do printf "$i"; done )
-bash: syntax error: `;' unexpected
-bash: syntax error: `(( i = j = k = 1; i % 9 || (j *= -1, $( ((i%9)) ||
printf " " >&2; echo 0), k++ <= 10); i += j ))'
Segmentation fault

The segfault on the subshell there is a bit odd if it were merely a syntax
error.

GNU bash, version 4.2.10(1)-release (x86_64-pc-linux-gnu)

-Dan Douglas


reply via email to

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