On 10.01.2023 21:10, Edward McGuire wrote:
I was reading manual pages for Bourne shell, and was surprised to see
the syntax of while-done documented as "while list [ do list ] done".
The surprise is that the do-list is bracketed (optional).
The brackets appear in the Unix Version 7 manual page published by
Sven Mascheck (https://www.in-ulm.de/~mascheck/bourne/v7/), and in
the manual page released by Gunnar Ritter with the Heirloom Bourne
shell (https://heirloom.sourceforge.net/sh/sh.1.html).
Is this just a long-standing documentation bug? The Heirloom shell
actually throws a syntax error when its input is "while true ;
done".
Is it [in Unix Version 7] a bug? - I suppose we'd need some old
(original) Bourne shell to test its behavior. - If it would work
in that old shell it could be considered an implementation error
in the clone. Code like i=5 ; while echo $i ; let i=i-1 ; done
would work. Anyway. Being curious I had a peek into the C source
code and (as far as I understood the macro'ized C code correctly)
the while statement expects a 'do' and a 'done'. A comment at the
beginning lists as an "item": "for ... while ... do ... done" ,
a syntax that resembles the Algol 68 generalized loop; which may
(as far as I can tell) be defined formally like
[ for v ] [ from f ] [ by b ] [ to t ] [ while w ] do s od
where almost everything is optional but the 'do' part. Despite
the Algol like "item" in Bourne shell 'for' and 'while' seem to
be separate commands (as we also know from the shell successors).
Interestingly I noticed that the 'for' loop does not seem to need
'do' and 'done'; these can be replaced by braces! - And that is
obviously still supported by some of the modern shells (ksh, zsh,
bash, but not, e.g., by ash):
$ for i in a b ; { echo $i ; }
a
b
(though this seems undocumented). - Funny anyway, and new to me.
Janis
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)