Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Is there a way to set a var above it's current scope?
- X-seq: zsh-workers 51458
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Is there a way to set a var above it's current scope?
- Date: Sat, 18 Feb 2023 16:29:54 +0100
- Archived-at: <https://zsh.org/workers/51458>
- In-reply-to: <CAKc7PVCGCCxS6bhRuFa=KN=hj0-tNfzA6pFMUoQbEG=yZuoDOA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAKc7PVCGCCxS6bhRuFa=KN=hj0-tNfzA6pFMUoQbEG=yZuoDOA@mail.gmail.com>
On Sat, Feb 18, 2023 at 3:57 PM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> Somewhere in the man I saw something like: if you use export you'll
> always set in global scope, regardless of any local variable
> collision.
You might be confusing it with the fact that `typeset -x q` is
equivalent to `typeset -gx q` and `export q` when used within a
function, even though normally `typeset` within a function is
equivalent to `local`.
> Is there any way of achieving this?
If there is a variable in function scope, there is no way to do
anything with the identically-named variable in global scope.
q=42
() {
local q;
# Nothing you can do here will have any
# effect on the global `q`.
}
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author