zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Global And Local Variables in zsh Functions
Date: Sat, 8 Aug 2015 17:31:47 -0700	[thread overview]
Message-ID: <150808173147.ZM14125@torch.brasslantern.com> (raw)
In-Reply-To: <55C68669.8000408@netcologne.de>

On Aug 9, 12:44am, Georg Wittig wrote:
}
} x1=$(my_f2 /tmp)
} x2=$(my_f2 /opt/windows7)
} 
} To my surprise, EXC is empty now:
} 
} Why is EXC empty in the case of my_f2, and correct in the case my_f1?

The use of $(...) means your my_f2 function runs in a forked child process,
and so changes to variables are not visible to the parent shell.  If you
want my_f2 to work like my_f1, you'll have to do something like

function my_f2 () {
    EXC+=" --exclude='$1'";
    typeset -g $2="some value depending on $1"
}

my_f2 /tmp x1
my_f2 /opt/windows7 x2


  parent reply	other threads:[~2015-08-09  0:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-08 22:44 Georg Wittig
2015-08-09  0:26 ` ZyX
2015-08-09  0:31 ` Bart Schaefer [this message]
2015-08-09  0:45 ` Mikael Magnusson

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=150808173147.ZM14125@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).