From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22948 invoked by alias); 21 Oct 2016 21:12:20 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22018 Received: (qmail 668 invoked from network); 21 Oct 2016 21:12:20 -0000 X-Qmail-Scanner-Diagnostics: from forward4o.cmail.yandex.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(37.9.109.248):SA:0(0.0/5.0):. Processed in 0.731021 secs); 21 Oct 2016 21:12:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM,SPF_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: kp-pav@yandex.ru X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf-ipv4.yandex.ru designates 37.9.109.248 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1477083984; bh=1g/W8XRXGMpYCpRaM6HZIAZ3cw4ekFArqWIqIiHFyaA=; h=From:To:In-Reply-To:References:Subject:Message-Id:Date; b=jhS4XlF8WMig5kGqP0kbAvy2yDCRN8cXh4bE0JqFTxURySJjFxZqCQflNZ+HisRFy O1+ShAQoskyoRgXKIfpMKkLaizzt0nNqYYWby0bQXSqDDs5qN2ZdyQ7atsX+GsZ+bD hJHesb/hTe6qDJICzipTKVpkGUgfYaecj70cekH0= Authentication-Results: mxback4h.mail.yandex.net; dkim=pass header.i=@yandex.ru From: "Nikolay Aleksandrovich Pavlov (ZyX)" To: Martijn Dekker , "zsh-users@zsh.org" In-Reply-To: <032fd4ec-89c1-9dae-a729-c440048ff3ec@inlv.org> References: <032fd4ec-89c1-9dae-a729-c440048ff3ec@inlv.org> Subject: Re: Checking if a variable is exported MIME-Version: 1.0 Message-Id: <4961661477083984@web22h.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Sat, 22 Oct 2016 00:06:24 +0300 Content-Transfer-Encoding: 7bit Content-Type: text/plain 21.10.2016, 23:34, "Martijn Dekker" : > Hi all, > > Does zsh have a straightforward way for a script to check if a variable > is exported? The closest-to-straightforward way I know of is to parse > the output of 'typeset -p varname', which is hairy because the output > might include various options to the command. > > Thanks, > > - M. I guess shortest version is something like zmodload zsh/parameter is_exported() { (( !! ${${(s.-.)parameters[$1]}[(Ie)export]} )) } or is_exported() { (( !! ${${(ts.-.)${(P)1}}[(Ie)export]} )) } (do not remember when (t) modifier was introduced, but AFAIR it is younger then zsh/parameter module). --- 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 : enclosing this thing into additional ${} like () { echo ${${(Pts.-.)1}} } PATH makes zsh echo $PATH value and not `scalar export special` like expected. Removing additional ${} neither works: () { echo ${(Pts.-.)1[1]} } PATH echoes `s` like if it was a space-separated string and not an array.