On 03/07/2012 04:54 PM, Jim Meyering wrote:
FYI, if I attempt to read into the built-in array variable, GROUPS,
this doesn't work:
$ bash -c 'while read GROUPS; do echo $GROUPS; done< /etc/passwd'|wc -l
0
Comparing with dash, I see what the author expected, i.e.,
that the while loop iterates once per line in /etc/passwd:
$ dash -c 'while read GROUPS; do echo $GROUPS; done< /etc/passwd'|wc -l
57
With bash, I can work around that by first doing "unset GROUPS".
Is there a moral here, other than to avoid using special variable names?
Probably to prefer lower-case variable names.
GROUPS An array variable containing the list of groups of which the
current user is a member. Assignments to GROUPS have no
effect
and return an error status. If GROUPS is unset, it
loses its
special properties, even if it is subsequently reset.
$ read GROUPS <<< "a"; echo $?
1
RR