zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Global array actually not available
Date: Thu, 30 Jun 2016 10:04:53 -0700	[thread overview]
Message-ID: <160630100453.ZM1682@torch.brasslantern.com> (raw)
In-Reply-To: <CAKc7PVCTQDEvtirfeZF-0885pXEZwvXbR+DvO9k-QoQWKYpVPg@mail.gmail.com>

On Jun 30,  4:34pm, Sebastian Gniazdowski wrote:
}
} In code, I declare reply2 and reply3 as arrays via typeset -ga. I do
} this from inside of a function. When the code returns to outer scope,
} (t)reply2 and (t)reply3 show empty strings.

I see your follow-up in which it appears this may be attributable to
separate shell processes, but in addition please note that typeset -g
does not actually declare a "global" variable (despite the mnemonic).
It merely declares a "non-local" variable.  The actual dynamic scope
of the variable will be the nearest surrounding scope in which that
parameter's name is already defined (even if both defined AND unset;
in the unset case it may become set again, but it's scope remains).

Thus "typeset -g name" declares a true global $name only when there
is not another $name already declared (or $name is already global,
of course).


      parent reply	other threads:[~2016-06-30 17:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-30 14:34 Sebastian Gniazdowski
2016-06-30 14:56 ` Sebastian Gniazdowski
2016-06-30 17:04 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160630100453.ZM1682@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).