bug-bash
[Top][All Lists]
Advanced

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

Re: Variable scoping


From: Matthew Markopoulos
Subject: Re: Variable scoping
Date: Wed, 19 Feb 2003 22:18:25 +0700

You wrote:
> > According to the bash manual, if I use typeset to declare a variable in
a
> > function, the scope of that variable will be restricted to the function
and
> > its children (because typeset acts like local). This works as I expect:
>
> Bash and ksh-88 work the same:  dynamic scoping.  When ksh-93 introduced
two
> subtly different types of shell functions, depending on their declaration,
> David introduced two different types of variable scoping.  Your analysis
is
> just about exactly correct.
>
> `POSIX' functions (name()) have no scoping at all.  Your test will print
> `0 0'.  `ksh' functions have lexical scoping.  Your test will print `15
15'.
> Just to make things more complicated, ksh allows lexically-scoped
variables
> to be exported in the environment, in which case they act as if they're
> dynamically scoped.
>
> The ksh93 documentation is misleading, at best.

Many thanks for this. It clears up a lot of confusion on my part.

I wonder if I may post your reply to comp.unix.shell, where I've started a
small thread on this?

Thanks,

Matt M





reply via email to

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