bug-bash
[Top][All Lists]
Advanced

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

Re: Variable scoping


From: Chet Ramey
Subject: Re: Variable scoping
Date: Wed, 19 Feb 2003 09:03:42 -0500

> 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.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )

Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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