For x in a b c; { list; } (in lieu of do list; done) works (in bash) - why and how?

In this post I came across the cited construct. It works! while ... { list; } does not.
man bash does not mention it (or, better, I didn't see it).

Any reason for / behind this? Am I missing something?

how about f() without braces?

mute@clt:~$ f() for x in 1 2 3; { echo $x; };
mute@clt:~$ f
1
2
3

implementation. somehow for got away with accepting a list, but while didn't. I would not rely on it, but it has saved me a few bytes with code golfing :slight_smile:

I think this undocumented syntax is still there for historical reasons and should not be used. I noticed it works in both old and new bash versions. It also works in zsh and ksh93, but not in ksh88. It is not POSIX compliant and does not work in dash.

Shells with that type of for-loop support typically also support an analogous select statement: select i in a b c; { echo $i; }

I have never used either myself. I see no benefit, only headaches.

Regards,
Alister

To be picky: An application using these features is not a strictly conforming POSIX application, but a shell that provides these features is not made non-compliant by providing this feature as an extension to the standard.

An application could be a POSIX conforming application using extensions if it documented that it needed a shell that supports this syntax and otherwise used only features documented by the POSIX standards.

Otherwise, as far as the standards are concerned, the behavior of an application using syntax that is not documented by the standard is unspecified.

:slight_smile: I like it when you're being picky. With "It is not .." , I meant "The use of these features is not.."