dash, ash for loop oddity
Hi,
according to the grammar
<http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_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 | [...] | linebreak : newline_list | | /* empty */
the following script should be legal:
#####
#!/bin/dash
for i
in a b c
do
echo $i
done
#####
but it fails with:
| ./a.sh: 3: Syntax error: "in" unexpected (expecting "do").
bash, zsh and NetBSDs ksh are doing fine while NetBSDs sh, based on ash fails, too.
Max
Quoted 5 lines · Maximilian Bernöcker
Hi,
according to the grammar
<http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_10_02>
Quoted 8 lines
| for_clause : For name linebreak do_group | | For name linebreak in sequential_sep do_group | | For name linebreak in wordlist sequential_sep do_group | [...] | linebreak : newline_list | | /* empty */the following script should be legal:
Thanks. Fixed with this patch.
commit 22e8fb41be2bfd0e6757c80d6365af9080a3b4a1
Author: Herbert Xu <[email protected]> Date: Sun Feb 22 19:47:52 2009 +0800
[PARSER] Allow newlines after var name in for statements
POSIX allows newlines before the "in" keyword in for statements so we should too.
Thanks to Maximilian Bernöcker for reporting this.
ChangeLog +1 -0
@@ -3,6 +3,7 @@ * Fix dowait signal race. * Remove EXSIG. * Do not close stderr when /dev/tty fails to open. + * Allow newlines after var name in for statements. 2009-01-14 Herbert Xu <[email protected]>
src/parser.c +2 -2
@@ -357,7 +357,7 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : "")); n1 = (union node *)stalloc (sizeof (struct nfor )); n1->type =NFOR ; n1->nfor.var = wordtext; - checkkwd =CHKKWD |CHKALIAS ; + checkkwd =CHKNL |CHKKWD |CHKALIAS ;if (readtoken () ==TIN ) { app = ≈while (readtoken () ==TWORD ) {
@@ -383,7 +383,7 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));* Newline or semicolon here is optional (but note * that the original Bourne shell only allowed NL). */ -if (lasttoken !=TNL && lasttoken !=TSEMI ) +if (lasttoken !=TSEMI ) tokpushback++; } checkkwd =CHKNL |CHKKWD |CHKALIAS ;
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt