|
From: | Roman Rakus |
Subject: | Re: using the variable name, GROUPS, in a read list |
Date: | Wed, 07 Mar 2012 17:05:20 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 |
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 thecurrent 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
[Prev in Thread] | Current Thread | [Next in Thread] |