Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Checking if a variable is exported
- X-seq: zsh-users 22021
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Checking if a variable is exported
- Date: Fri, 21 Oct 2016 22:57:38 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=FeBh3wpn6acSEf/seX7jZDgXdmCsx02eeQvYLPBVeRo=; b=yta1Na64XozXY1U3L8fBXasP1jCLMpAlH3vSzNuwt0be4AjAoKdy5lC88lTHsWIYL2 xR23GFhC+5Cnnp02vM0D3O6dg0652Icq9LyATNH/kc6Tjtc4oD9BLvbo/cwJ/evltEDk mQzf19uBzA6K46/ZWTLdxE9GHqpeliGil5wpoadjphqtKk1hxjKUWm8EVg1UKE6+SM4O yx164qyphNdYx2IiPDnX+ADho/CoTDbhgoqINKRpdjuOisGflvaIsluQQ82Bq8crUcDD uqWJ+bQBg+HEoJnryM4Un3PMH+/5bSiGk7v8ejHuPuIScXIAKBPIsb9K7JodU8YtQcOd ztVQ==
- In-reply-to: <4961661477083984@web22h.yandex.ru>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <032fd4ec-89c1-9dae-a729-c440048ff3ec@inlv.org> <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author