bug-bash
[Top][All Lists]
Advanced

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

Re: [50 character or so descriptive subject here (for reference)] env va


From: Al Elgert
Subject: Re: [50 character or so descriptive subject here (for reference)] env variables dropped by bash-2.05
Date: Tue, 15 Jan 2002 10:35:27 +0100
User-agent: Mutt/1.3.25i

On Mon, Jan 14, 2002 at 12:49:50PM -0500, Paul Jarc wrote:
> address@hidden (Al Elgert) wrote:
> > And now consider this function:
> >     bash-2.05$ function fff() { local i=0 x; x=10; echo "|$i|$x|"; }
> >     bash-2.05$ fff
> >     |0|10|
> >     bash-2.05$ x=1 fff
> >     |0|10|
> 
> This output is correct.  If you want the function to be sensitive to
> an environment variable setting, you have to write it that way:
> fff() { local i=0 x="${x-10}"; echo "|$i|$x|"; }

This does not work, as expected - can I have the Output of your test ?


It is useless to use a Variable as a local Value, if you override the
environment then the Variable is of no use in the function:

        bash-2.05$ fff() { local i=0 x="${x-10}"; echo "|$i|$x|"; }
        bash-2.05$ x=11 fff
        |0||

        bash-2.04$ fff() { local i=0 x="${x-10}"; echo "|$i|$x|"; }
        bash-2.04$ x=11 fff
        |0|11|

The output in bash-2.05 schould be "|0|11|" OR "|0|10|" but it is "|0||".

changing the function, where x is defined local and then assigned separately
gives a result which is just as bad:

        bash-2.05$ fff() { local i=0 x; x="${x-10}"; echo "|$i|$x|"; }
        bash-2.05$ x=11 fff
        |0|10|

        bash-2.04$ fff() { local i=0 x; x="${x-10}"; echo "|$i|$x|"; }
        bash-2.04$ x=11 fff
        |0|11|

again, the assignment "x=11" is ignored by the bash-2.05.

The bash-2.05 destroys any variable given in this way including the local
variables of the function, this is a total change to bash-2.04.
I don't think it is a good idea to drop these variables completely.

greetings
        Alexander

PS:     my .bashrc is too big *sigh*
        -rwxr-xr-x   1 elgert   student    412927 Jan 14 17:56 .bashrc

PPS:
        I wrote a few portable functions, which could be placed as examples
        in the bash distribution. If it is to your interest, please contact me.

-- 
Alexander Elgert
Public Gruppe
RechnerBetriebsGruppe    TU Darmstadt  (FB 20)   Tel:  +49 06151 16-4333
                                                 Raum: S1/13 11a (alt 25/11a)



reply via email to

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