pkgsrc-Bugs archive

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

Re: pkg/51142: pdksh has occasional issues with empty 'for' loops



The following reply was made to PR pkg/51142; it has been noted by GNATS.

From: Richard PALO <richard%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: pkg/51142: pdksh has occasional issues with empty 'for' loops
Date: Mon, 16 May 2016 06:52:36 +0200

 Le 15/05/16 19:30, Joerg Sonnenberger a écrit :
 >  That's not a shell bug, but a "feature" of the standard. A common
 >  pattern found e.g. in mk/ is to explicit append '' (empty string) and
 >  short cut with [ -n "$i" ] || break
 >  
 >  Joerg
 
 Indeed! 
 http://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html#tag_02_14
 does say:
 > The format for the for loop is as follows:
 > 
 >     for name [ in [word ... ]]do
 >         compound-list
 > 
 > 
 >     done
 > 
 > First, the list of words following in shall be expanded to generate a list of items.
 > Then, the variable name shall be set to each item, in turn, and the compound-list
 > executed each time. If no items result from the expansion, the compound-list shall
 > not be executed. Omitting:
 > 
 >     in word ...
 > 
 > shall be equivalent to:
 > 
 >     in "$@"
 > 
 
 and using "set dummy; shift" prior to the 'for' loop gets over the yelp problem too.
 
 So it looks as if pdksh inadvertently performs the "$@" substitution even if the "in" remains.
 
 Testing again bash and ksh93, ommiting the "in" gives 'dummy' as with pdksh so it does
 look like pdksh is the culprit here.
 
 cheers,
 -- 
 Richard PALO
 


Home | Main Index | Thread Index | Old Index