zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: zsh-newuser-install
Date: Sat, 26 Apr 2014 21:21:26 +0100	[thread overview]
Message-ID: <20140426212126.58b0ff26@pws-pc.ntlworld.com> (raw)
In-Reply-To: <slrnlln1bj.a9l.martin@epidot.math.uni-rostock.de>

On Sat, 26 Apr 2014 10:07:47 +0000 (UTC)
Martin Vaeth <martin@mvath.de> 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 <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2014-04-26 20:27 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-16 14:35 setopt interactivecomments shawn wilson
2014-04-16 17:27 ` Bart Schaefer
2014-04-16 17:37   ` shawn wilson
2014-04-17 14:37     ` Ray Andrews
2014-04-17 19:37       ` Bart Schaefer
2014-04-17 21:36         ` Ray Andrews
2014-04-17 22:07           ` shawn wilson
2014-04-17 22:48             ` Bart Schaefer
2014-04-17 23:51               ` shawn wilson
2014-04-17 22:41           ` Bart Schaefer
2014-04-18  3:10             ` Ray Andrews
2014-04-18 11:59             ` Roman Neuhauser
2014-04-23 15:50         ` zsh-newuser-install Peter Stephenson
2014-04-23 20:31           ` zsh-newuser-install Yuri D'Elia
2014-04-23 23:53             ` zsh-newuser-install Mikael Magnusson
2014-04-24  6:23               ` zsh-newuser-install Yuri D'Elia
2014-04-24 14:34                 ` zsh-newuser-install Ray Andrews
2014-04-24 16:02                   ` zsh-newuser-install Yuri D'Elia
2014-04-25  1:38                     ` zsh-newuser-install Ray Andrews
2014-04-24 16:04                   ` zsh-newuser-install Axel Beckert
2014-04-25 15:43               ` zsh-newuser-install Martin Vaeth
2014-04-25 16:21                 ` zsh-newuser-install Peter Stephenson
2014-04-26 10:07                   ` zsh-newuser-install Martin Vaeth
2014-04-26 20:21                     ` Peter Stephenson [this message]
2014-04-26 20:38                     ` zsh-newuser-install Bart Schaefer
2014-04-25 17:03                 ` zsh-newuser-install Bart Schaefer
2014-04-26 13:49                 ` zsh-newuser-install Yuri D'Elia
2014-04-26 21:10                   ` zsh-newuser-install Bart Schaefer
2014-04-28 17:35                     ` zsh-newuser-install Bart Schaefer
2014-04-24  1:05           ` zsh-newuser-install Ray Andrews
2014-04-17 19:04     ` setopt interactivecomments Bart Schaefer

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=20140426212126.58b0ff26@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).