From: Bart Schaefer <schaefer@brasslantern.com>
To: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: Checking if a variable is exported
Date: Fri, 21 Oct 2016 22:57:38 -0700 [thread overview]
Message-ID: <161021225738.ZM10714@torch.brasslantern.com> (raw)
In-Reply-To: <4961661477083984@web22h.yandex.ru>
On Oct 22, 12:06am, Nikolay Aleksandrovich Pavlov (ZyX) wrote:
}
} BTW, if I use
}
} () { echo ${(Pts.-.)1} } PATH
}
} I get `scalar export special` like expected. But I always get return
} status 1 when using
}
} () { (( !! ${${(Pts.-.)1}[(Ie)export]} )) } PATH
This is explained in the doc for (P):
... if the reference is itself nested, the expression with
the flag is treated as if it were directly replaced by the
parameter name. It is an error if this nested substitution
produces an array with more than one word. For example, if
`name=assoc' where the parameter assoc is an associative array,
--> then `${${(P)name}[elt]}' refers to the element of the associative
--> subscripted `elt'.
And then later:
Note that, unless the `(P)' flag is present, the flags and any
subscripts apply directly to the value of the nested substitution;
for example, the expansion ${${foo}} behaves exactly the same as
--> ${foo}. When the `(P)' flag is present in a nested substitution,
--> the other substitution rules are applied to the value _before_ it
--> is interpreted as a name, so ${${(P)foo}} may differ from
${(P)foo}.
So what you need is to isolate ${(P)1} from all other parameter flags
and also separate it from the subscript expression:
torch% () { echo ${(ts.-.)${(P)1}} } PATH
scalar export special
torch% () { echo ${${(ts.-.)${(P)1}}[(I)export]} } PATH
2
next prev parent reply other threads:[~2016-10-22 6:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-21 20:27 Martijn Dekker
2016-10-21 21:00 ` Eric Cook
2016-10-21 21:06 ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-10-22 5:57 ` Bart Schaefer [this message]
2016-10-21 21:12 ` 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=161021225738.ZM10714@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).