From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20696 invoked by alias); 15 Sep 2016 13:52:07 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39347 Received: (qmail 23791 invoked from network); 15 Sep 2016 13:52:07 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf0-f44.google.com 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(209.85.215.44):SA:0(0.0/5.0):. Processed in 0.191529 secs); 15 Sep 2016 13:52:07 -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: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.215.44 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=cl9lBt9qgYoSNHuJOltE9HIekwK6MsOEwiCfiKS/Fbk=; b=I4YEqwmD2x7R/kOTLozbvHeKYPKI7PSvmfx325FDg8rUsms5gu3O6A+LWBQ+0fF7p/ UpBb07qHSHQFnOjJJGMZ1rExXmk6F4atLQMus8UR3eyjK3C1AMOlTy1ZIiP4sBjKknYj vHD9l4wdTAHDPbrTdoAEb3brQ7q9hFcQsfL0i9J4it3XbsiZXVn489Wiy7APH08m7Zps opWwHSB/2LW0rnBT2f8DrWku5T4w8QzRG4UgezqHUlMCl9FUDBy2vUvAmKOvoORk7V0h LxizHmKKjzvn8cxTVPXmPgGWKtXc5qCk+cIQrMjQXxSpk4xUnH+a7hVQ+gLA9RAFr8mw i41w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=cl9lBt9qgYoSNHuJOltE9HIekwK6MsOEwiCfiKS/Fbk=; b=Ml3jsqipE+fI9sBoXjhjm6ZqlYPaqDKZ4bKPp12ncOCqTtFIyIqjwQmdXb444mbQ8e LlUf1pGmZ+vhMs5EztfCj8NaYMdHvq/px+ugOqcwYtpnb3WBYJIKEqRw1ps3RF3Jc8gZ RLTkE05qupQzB/mBYmGsgqpFOW4o/0O0J5vdKsFlHEqlYd/hDssygRcMQlCk3okLl70B VassffN/Z7DuCQo9NdY+NcYTH7qk8pVhow2HoUHCzNts6lf1DlR34OI4sZdtc9ZyTepx UAkcid6LRzidNvjVtl9dkIDy0mkGCcUZOmvtyxXEzEiGo+6fHdHqMAXq9Twgy1kaRqFS vEZw== X-Gm-Message-State: AE9vXwOcqa93LS+LXCOU1/wrHPD+CQp01dCyMMYt7gRtM9+la4UilCxFQJTeNHr8O2umCg== X-Received: by 10.28.46.204 with SMTP id u195mr2323960wmu.57.1473937741223; Thu, 15 Sep 2016 04:09:01 -0700 (PDT) Date: Thu, 15 Sep 2016 12:08:55 +0100 From: Stephane Chazelas To: Oliver Kiddle Cc: zsh-workers@zsh.org Subject: Re: PATCH: [[ -v varname ]] Message-ID: <20160915110854.GA10122@chaz.gmail.com> Mail-Followup-To: Oliver Kiddle , zsh-workers@zsh.org References: <20160905212754.24998-1-tgyurci@gmail.com> <20160908093516.4fc2dd1e@pwslap01u.europe.root.pri> <20160908121628.78977edd@pwslap01u.europe.root.pri> <20160908143128.GA14933@chaz.gmail.com> <20160909085231.GA9717@chaz.gmail.com> <90414.1473890510@hydra.kiddle.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <90414.1473890510@hydra.kiddle.eu> User-Agent: Mutt/1.5.21 (2010-09-15) 2016-09-15 00:01:50 +0200, Oliver Kiddle: > On 9 Sep, Stephane Chazelas wrote: > > You guys may want to comment on the latest proposal there: > > http://austingroupbugs.net/file_download.php?file_id=31&type=bug > > as it would make zsh non-conformant. > > One thing it also includes is the bash/ksh [[ -v ... ]] condition for > checking if a particular variable is set. Zsh has the ${+varname} syntax > which provides the same functionality in a different form. The following > patch adds the ksh form for compatibility. [...] Note that there's a lot of variation between the ksh93 and bash implementation of [[ -v ]] (though maybe not so much on the part covered by POSIX), for instance on variables that have been declared (or exported or marked readonly) with different types but not assigned to (at least in zsh, declared/exported variables are always given a default value), on arrays or hashs that have no element (or no element of indice 0 or "0"; for a hash in bash [[ -v h ]] returns true iff h[0] is set and in ksh never ([[ -v h[@] ]] doesn't work either)). Also note that in ksh/bash, it's only for variables, not other types of parameters ([[ -v 0 ]], [[ -v "#" ]] return false). See also: $ a='b[0`uname>&2`]' bash -c '[[ -v $a ]]' Linux $ bash -c 'typeset -n a=b; [[ -v a ]]'; echo $? 1 $ b= bash -c 'typeset -n a=b; [[ -v a ]]'; echo $? 0 Spurious error message: $ ksh -c 'typeset -T A=(a=a); A a; [[ -v a.x ]]' ksh: x: is not an element of a a.x returns false if $a has a x but that's a discipline (or array/hash with 0 element not set). In any case, it looks like your patch does the sensible thing in all the cases I've tried except that [[ -v @ ]] returns false (while [[ -v * ]] return true). No big deal as nobody would ever want to do that. What to do in zsh (where scalar and arrays are distinct types) for zsh -c 'a=1234; [[ -v a[1] ]] is up to debate (currently returns false). See also https://unix.stackexchange.com/questions/212183/how-do-i-check-if-a-variable-exists-in-an-if-statement/246703#246703 -- Stephane