On Wed, Mar 07, 2012 at 04:54:14PM +0100, Jim Meyering wrote: > Is there a moral here, other than to avoid using special variable names? > Probably to prefer lower-case variable names.
You've nailed it. Or more precisely, avoid all-upper-case variable names, because they tend to collide with environment variables and special shell variables. Any variable name with at least one lower-case letter should be safe. There is an unfortunate long-lived bad habit that's floating around out there, where people think they're supposed to use all-caps variable names in shell scripts. That is not a good idea, and you've just stumbled upon one of the many reasons why.