[Top][All Lists]

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

Re: Bash 4.1 doesn't behave as I think it should: arrays and the environ

From: Greg Wooledge
Subject: Re: Bash 4.1 doesn't behave as I think it should: arrays and the environment
Date: Fri, 17 Aug 2012 17:18:12 -0400
User-agent: Mutt/

On Fri, Aug 17, 2012 at 03:19:56PM +0800, John Summerfield wrote:
> In two cases I wish to pass an array in the environment, like so:
> 14:28 address@hidden STUFF[1]=one STUFFX=stuffx env | grep ^ST
> STUFFX=stuffx
> STUFF[1]=one

You are creating an environment variable called "STUFF[1]".  This is
an invalid environment variable name, but env(1) receives it and
dutifully prints it out.  However, Bash recognizes that it is an
invalid name, and does not turn it into a usable shell variable.

Some older versions of Bash would also strip such invalid variables
from the environment before invoking child processes.  Bash 4.2
leaves them in the environment because of complaints about build
systems that were using them for some purpose.  I don't know whether
Bash 4.1 is one that stripped them or preserved them.  In either
case, you should not be writing programs that rely on invalid variable

reply via email to

[Prev in Thread] Current Thread [Next in Thread]