Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh-newuser-install



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



Messages sorted by: Reverse Date, Date, Thread, Author