[Top][All Lists]

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

Misleading syntax in manual

From: Reuben Thomas
Subject: Misleading syntax in manual
Date: Mon, 6 Apr 2009 22:57:30 +0100 (BST)
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)

The syntax for the "for" command is misleading, as although correct for bash, it is not POSIX-compliant.

I am using GNU bash, version 3.2.48(1)-release (i486-pc-linux-gnu)

The man page says:

for name [ in word ] ; do list ; done

which conflicts with the POSIX syntax definition, given in


which says:

    for name [ in [word ... ]]do


Note that in the POSIX definition, a semi-colon is only needed, and indeed permitted, after the word list when an "in" clause is used. Hence:

for i; do

is not correct in POSIX, although it is accepted by bash. (I found this while trying to build GNU Zile on Solaris.) bash does, of course, accept the POSIX syntax.

The easiest fix seems to be to put the semicolon above in square brackets, making it optional, though this risks giving the impression that the syntax

for i in foo bar;; do

would be acceptable, when it's not (even by bash). So, you could give two explicit definitions:

for i [;] do list ; done


for i in word ; do list ; done

My dark path darkens; rise over the mountain, distant moon (Murasaki)
Listening to: 'Sanctus and Benedictus' from 'Mass of the Children and other
sacred music' (The Cambridge Singers / John Rutter)

reply via email to

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