Red Hat Bugzilla – Bug 10894
can't set GROUPS until after it's echoed
Last modified: 2008-05-01 11:37:55 EDT
> bash -c 'GROUPS=foo; echo $GROUPS'
> bash -c 'echo $GROUPS; GROUPS=foo; echo $GROUPS'
Why do you want to set a read-only variable?
1) It wasn't me, it was a shell script I inherited. I patched around the
problem by changing the variable name, but still, a shell script shouldn't break
in indetermine ways simply because it has the bad luck of choosing a variable
name that bash reserves (speaking of which, where does bash get off reserving
variable names without putting underscores in front of their names or something
to protect the namespace? but I digress).
2) The bash man page (at least in bash-2.04-4) does not document that GROUPS is
a read-only variable.
3) Well, OK, it *sort of* documents this, since it says that assignments to the
variable are silently discarded (that's really broken; if bash is going to
reserve a variable and not allow its value to be changed, and a shell script
tries to change the variable, bash should immediately crap out, or at least
print an error message, so you have some idea of what's going wrong). But in
that case, the bug is that I *was* able to change the value of the variable
after echoing it. That's clearly broken.
Please discuss this with firstname.lastname@example.org - we can't just change bash's behavior for compatibility reasons with other distributions/OSes using bash.