* Is there a way to set a var above it's current scope?
@ 2023-02-18 14:55 Sebastian Gniazdowski
2023-02-18 15:29 ` Roman Perepelitsa
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2023-02-18 14:55 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 240 bytes --]
Hi,
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. However,
(){local q; export q=1;};print $q doesn't print 1. Is there any way of
achieving this?
[-- Attachment #2: Type: text/html, Size: 318 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Is there a way to set a var above it's current scope?
2023-02-18 14:55 Is there a way to set a var above it's current scope? Sebastian Gniazdowski
@ 2023-02-18 15:29 ` Roman Perepelitsa
2023-02-18 16:17 ` Sebastian Gniazdowski
0 siblings, 1 reply; 3+ messages in thread
From: Roman Perepelitsa @ 2023-02-18 15:29 UTC (permalink / raw)
To: Sebastian Gniazdowski; +Cc: Zsh hackers list
On Sat, Feb 18, 2023 at 3:57 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Is there a way to set a var above it's current scope?
2023-02-18 15:29 ` Roman Perepelitsa
@ 2023-02-18 16:17 ` Sebastian Gniazdowski
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Gniazdowski @ 2023-02-18 16:17 UTC (permalink / raw)
To: Roman Perepelitsa; +Cc: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]
Yes I know, also one can use local at global scope to have the same effect
as typeset -g there, this is a direct effect of how scopes are implemented.
sob., 18 lut 2023, 16:30 użytkownik Roman Perepelitsa <
roman.perepelitsa@gmail.com> napisał:
> On Sat, Feb 18, 2023 at 3:57 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> 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.
>
[-- Attachment #2: Type: text/html, Size: 1506 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-18 16:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 14:55 Is there a way to set a var above it's current scope? Sebastian Gniazdowski
2023-02-18 15:29 ` Roman Perepelitsa
2023-02-18 16:17 ` Sebastian Gniazdowski
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).