From: Peng Yu <pengyu.ut@gmail.com>
To: zsh-users <zsh-users@zsh.org>
Subject: Why local is needed?
Date: Sun, 2 Dec 2018 20:38:44 -0600 [thread overview]
Message-ID: <CABrM6wmeG8mT2ke6+ObQAqY7qTqxKnb2GyD1f5AGb141m0hkyQ@mail.gmail.com> (raw)
Hi,
It seems that the variables used in a function by default are local
anyway. Does it mean that the command `local` is never necessary in a
function if the variables are specified as local variables? Thanks.
$ cat ./main.sh
#!/usr/bin/env zsh
# vim: set noexpandtab tabstop=2:
set -v
function f {
x=1
y=(a b c)
}
declare -p x y
$ ./main.sh
function f {
x=1
y=(a b c)
}
declare -p x y
./main.sh:declare:10: no such variable: x
./main.sh:declare:10: no such variable: y
--
Regards,
Peng
next reply other threads:[~2018-12-03 2:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-03 2:38 Peng Yu [this message]
2018-12-03 4:47 ` Eric Cook
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=CABrM6wmeG8mT2ke6+ObQAqY7qTqxKnb2GyD1f5AGb141m0hkyQ@mail.gmail.com \
--to=pengyu.ut@gmail.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).