From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12389 invoked by alias); 26 Apr 2014 20:27:11 -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: 18775 Received: (qmail 3859 invoked from network); 26 Apr 2014 20:27:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [86.6.157.246] X-Spam: 0 X-Authority: v=2.1 cv=bdnlUY/B c=1 sm=1 tr=0 a=BvYiZ/UW0Fmn8Wufq9dPrg==:117 a=BvYiZ/UW0Fmn8Wufq9dPrg==:17 a=NLZqzBF-AAAA:8 a=uObrxnre4hsA:10 a=kj9zAlcOel0A:10 a=ee9NthGkJbhy4sUCLFcA:9 a=CjuIK1q_8ugA:10 a=XkS7lJdTqAAA:10 a=_dQi-Dcv4p4A:10 Date: Sat, 26 Apr 2014 21:21:26 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: zsh-newuser-install Message-ID: <20140426212126.58b0ff26@pws-pc.ntlworld.com> In-Reply-To: References: <140416102727.ZM19090@torch.brasslantern.com> <534FE710.3020601@eastlink.ca> <140417123722.ZM22179@torch.brasslantern.com> <20140423165024.1480528a@pws-pc.ntlworld.com> <20140425172112.7bf50606@pwslap01u.europe.root.pri> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 26 Apr 2014 10:07:47 +0000 (UTC) Martin Vaeth wrote: > BTW: "emulate -L bash" would be useful to read some distribution's > or user's bash setup files. Main difference to emulate -L sh would be > setopt ksh_glob no_sh_glob brace_expand > and that [[ $var ]] is treated equivalent to [[ -n $var ]]: > I experienced that the latter is the main issue with bash compatibility > (besides shopt and PS1, of course, which are not reasonable to emulate). This is easy to fix; the syntax wasn't valid up till now so there's no conflict in enabling it. diff --git a/Doc/Zsh/cond.yo b/Doc/Zsh/cond.yo index 9f8a7d8..a796834 100644 --- a/Doc/Zsh/cond.yo +++ b/Doc/Zsh/cond.yo @@ -186,6 +186,13 @@ true if either var(exp1) or var(exp2) is true. ) enditem() +For compatibility, if there is a single argument that is not +syntactically significant, typically a variable, the condition is +treated as a test for whether the expression expands as a string of +non-zero length. In other words, tt([[ $var ]]) is the same as tt([[ -n +$var ]]). It is recommended that the second, explicit, form be used +where possible. + Normal shell expansion is performed on the var(file), var(string) and var(pattern) arguments, but the result of each expansion is constrained to be a single word, similar to the effect of double quotes. diff --git a/Src/parse.c b/Src/parse.c index 530a070..7957448 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -2127,6 +2127,11 @@ par_cond_2(void) dble = (*s1 == '-' && strspn(s1+1, "abcdefghknoprstuwxzLONGS") == 1 && !s1[2]); condlex(); + if (tok == DOUTBRACK) + { + /* allow [[ $testsize ]] for compatibility */ + return par_cond_double(dupstring("-n"), s1); + } if (tok == INANG || tok == OUTANG) { enum lextok xtok = tok; condlex(); diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 94fca8b..6900147 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -349,6 +349,14 @@ F:Failures in these cases do not indicate a problem in the shell. >0 >1 + foo='' + [[ $foo ]] || print foo is empty + foo=full + [[ $foo ]] && print foo is full +0:bash compatibility with single [[ ... ]] argument +>foo is empty +>foo is full + %clean # This works around a bug in rm -f in some versions of Cygwin chmod 644 unmodish -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/