help / color / mirror / Atom feed
From: "Jun. T" <takimoto-j@kba.biglobe.ne.jp>
To: zsh-users@zsh.org
Cc: Yasuhiro KIMURA <yasu@utahime.org>
Subject: Re: Avoid duplication of code
Date: Mon, 25 May 2020 23:22:39 +0900
Message-ID: <D7E7657E-0281-4537-825A-2D3021461A67@kba.biglobe.ne.jp> (raw)
In-Reply-To: <20200525.180259.1237420001357827351.yasu@utahime.org>

> 2020/05/25 18:02, Yasuhiro KIMURA <yasu@utahime.org> wrote:
> 1. Define function that updates single environment variable and pass
>   variable name as argument of it.
> 2. Use 'for name in word; do list done' such as following.
>      for valname in SSH_AUTH_SOCK SSH_AGENT_PID
>      do
>        (update value of environment variable named ${valname})
>      done
> But it seems that both require nested variable expansion and that it
> is impossible. Then is there any other way to avoid code duplication?

Suppose a parameter, say valname, contains a name of another parameter;


Then you can GET the current value of SSH_AUTH_SOCK by

if [[ -n ${(P)valname} ]]; then ...

You can SET a new value to SSH_AUTH_SOCK in a couple of ways.
In your case, probably

export $valname='new value'

would be the simplest. If you don't want to export the variable, then,

: ${(P)valname::=new value}

  reply	other threads:[~2020-05-25 14:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25  9:02 Yasuhiro KIMURA
2020-05-25 14:22 ` Jun. T [this message]
2020-05-28  8:05   ` Yasuhiro KIMURA
2020-05-28  8:53     ` Daniel Shahaf
2020-05-28 10:24       ` Yasuhiro KIMURA

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:

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

  git send-email \
    --in-reply-to=D7E7657E-0281-4537-825A-2D3021461A67@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=yasu@utahime.org \
    --cc=zsh-users@zsh.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link


This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ http://inbox.vuxu.org/zsh-users \
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:

code repositories for the project(s) associated with this inbox:


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git