bug-bash
[Top][All Lists]
Advanced

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

Re: Misleading syntax in manual


From: Eric Blake
Subject: Re: Misleading syntax in manual
Date: Wed, 08 Apr 2009 06:10:18 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Reuben Thomas on 4/6/2009 3:57 PM:
> The man page says:
> 
> for name [ in word ] ; do list ; done
> 
> which conflicts with the POSIX syntax definition, given in
> 
> http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02

The corresponding link in POSIX 2008 is:

http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_04

although the expository listing in that section is misleading.  The REAL
POSIX definition is given later in the grammar:

http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02

for_clause       : For name linebreak                            do_group
                 | For name linebreak in          sequential_sep do_group
                 | For name linebreak in wordlist sequential_sep do_group
do_group         : Do compound_list Done           /* Apply rule 6 */
linebreak        : newline_list
                 | /* empty */


Which means the POSIX-mandated syntax should really be represented as:

for name [in [word...] ;] do
  compound-list
done

I guess we should file a bug report to the Austin group.

> 
> 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
> 
> and
> 
> for i in word ; do list ; done

You missed word... (the ... is important).  To keep it on one line, I'd
represent the bash syntax as:

for name [ in [ name ... ] ; | ; ] do

to show that bash supports four varints: 'in ;', 'in name... ;', ';', or
blank.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAknclCoACgkQ84KuGfSFAYC+3ACgpuEfKgSslKM2Vnl1sv3i69PW
XnMAmQFfqIhjHgwHlB5q7ExsCsR9hXi4
=bD+a
-----END PGP SIGNATURE-----




reply via email to

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