zsh-workers
 help / color / mirror / code / Atom feed
* zsh regards reserved word as candidate for alias substitution
@ 2009-02-25  0:17 Vincent Lefevre
  2009-03-03 17:23 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Lefevre @ 2009-02-25  0:17 UTC (permalink / raw)
  To: zsh-workers

I've reported the following bug on

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=516998

POSIX.1-2008 says[*]:

  2.3.1 Alias Substitution
  [...] However, reserved words in correct grammatical context
  shall not be candidates for alias substitution.

[*] http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_03_01

but zsh gives:

vin% emulate sh
vin% alias !="echo OK"
vin% ! foo
OK foo
vin% 

instead of running command "foo". ksh93, pdksh, dash and bash
in POSIX mode all behave correctly.

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: zsh regards reserved word as candidate for alias substitution
  2009-02-25  0:17 zsh regards reserved word as candidate for alias substitution Vincent Lefevre
@ 2009-03-03 17:23 ` Peter Stephenson
  2009-03-03 17:33   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2009-03-03 17:23 UTC (permalink / raw)
  To: zsh-workers

On Wed, 25 Feb 2009 01:17:17 +0100
Vincent Lefevre <vincent@vinc17.org> wrote:
> I've reported the following bug on
> 
>   http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=516998
> 
> POSIX.1-2008 says[*]:
> 
>   2.3.1 Alias Substitution
>   [...] However, reserved words in correct grammatical context
>   shall not be candidates for alias substitution.

It's hardly worth an option, but it's best to keep options doing what they
say...

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.76
diff -u -r1.76 options.yo
--- Doc/Zsh/options.yo	14 Feb 2009 13:35:37 -0000	1.76
+++ Doc/Zsh/options.yo	3 Mar 2009 17:22:02 -0000
@@ -1708,6 +1708,43 @@
 This option is for compatibility with older versions of the shell and
 is not recommended in new code.
 )
+pindex(POSIX_ALIASES)
+pindex(NO_POSIX_ALIASES)
+pindex(POSIXALIASES)
+pindex(NOPOSIXALIASES)
+item(tt(POSIX_ALIASES) <K> <S>)(
+When this option is set, reserved words are not candidates for
+alias expansion:  it is still possible to declare any of them as an alias,
+but the alias will never be expanded.  Reserved words are
+tt(!),
+tt([[),
+tt({),
+tt(}),
+tt(case),
+tt(coproc),
+tt(do),
+tt(done),
+tt(elif),
+tt(else),
+tt(end),
+tt(esac),
+tt(fi),
+tt(for),
+tt(foreach),
+tt(function),
+tt(if),
+tt(nocorrect),
+tt(repeat),
+tt(select),
+tt(then),
+tt(time),
+tt(until),
+tt(while).
+
+Alias expansion takes place while text is being read; hence when this
+option is set it does not take effect until the end of any function or
+other piece of shell code evaluated as one unit.
+)
 pindex(POSIX_BUILTINS)
 pindex(NO_POSIX_BUILTINS)
 pindex(POSIXBUILTINS)
Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.51
diff -u -r1.51 lex.c
--- Src/lex.c	27 Feb 2009 10:24:16 -0000	1.51
+++ Src/lex.c	3 Mar 2009 17:22:02 -0000
@@ -1748,9 +1748,11 @@
 
 	if (tok == STRING) {
 	    /* Check for an alias */
-	    if (!noaliases && isset(ALIASESOPT)) {
+	    if (!noaliases && isset(ALIASESOPT) &&
+		(!isset(POSIXALIASES) ||
+		 !reswdtab->getnode(reswdtab, zshlextext))) {
 		char *suf;
-		
+
 		an = (Alias) aliastab->getnode(aliastab, zshlextext);
 		if (an && !an->inuse &&
 		    ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) {
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.47
diff -u -r1.47 options.c
--- Src/options.c	11 Feb 2009 20:42:16 -0000	1.47
+++ Src/options.c	3 Mar 2009 17:22:02 -0000
@@ -198,6 +198,7 @@
 {{NULL, "octalzeroes",        OPT_EMULATE|OPT_SH},	 OCTALZEROES},
 {{NULL, "overstrike",	      0},			 OVERSTRIKE},
 {{NULL, "pathdirs",	      OPT_EMULATE},		 PATHDIRS},
+{{NULL, "posixaliases",       OPT_EMULATE|OPT_BOURNE},	 POSIXALIASES},
 {{NULL, "posixbuiltins",      OPT_EMULATE|OPT_BOURNE},	 POSIXBUILTINS},
 {{NULL, "posixidentifiers",   OPT_EMULATE|OPT_BOURNE},	 POSIXIDENTIFIERS},
 {{NULL, "printeightbit",      0},                        PRINTEIGHTBIT},
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.153
diff -u -r1.153 zsh.h
--- Src/zsh.h	19 Feb 2009 10:12:39 -0000	1.153
+++ Src/zsh.h	3 Mar 2009 17:22:02 -0000
@@ -1933,6 +1933,7 @@
     OCTALZEROES,
     OVERSTRIKE,
     PATHDIRS,
+    POSIXALIASES,
     POSIXBUILTINS,
     POSIXIDENTIFIERS,
     PRINTEIGHTBIT,
Index: Test/A02alias.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A02alias.ztst,v
retrieving revision 1.6
diff -u -r1.6 A02alias.ztst
--- Test/A02alias.ztst	27 Mar 2008 09:41:13 -0000	1.6
+++ Test/A02alias.ztst	3 Mar 2009 17:22:02 -0000
@@ -25,3 +25,14 @@
   \bar \bar
 0:Aliasing with a backslash
 >bar
+
+  (alias '!=echo This command has the argument'
+  eval 'print Without
+  ! true'
+  setopt posixaliases
+  eval 'print With
+  ! true')
+1:POSIX_ALIASES option
+>Without
+>This command has the argument true
+>With

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: zsh regards reserved word as candidate for alias substitution
  2009-03-03 17:23 ` Peter Stephenson
@ 2009-03-03 17:33   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2009-03-03 17:33 UTC (permalink / raw)
  To: zsh-workers

On Tue, 3 Mar 2009 17:23:24 +0000
Peter Stephenson <pws@csr.com> wrote:
> +but the alias will never be expanded.  Reserved words are

Probably better:

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.77
diff -u -r1.77 options.yo
--- Doc/Zsh/options.yo	3 Mar 2009 17:26:07 -0000	1.77
+++ Doc/Zsh/options.yo	3 Mar 2009 17:31:57 -0000
@@ -1715,31 +1715,9 @@
 item(tt(POSIX_ALIASES) <K> <S>)(
 When this option is set, reserved words are not candidates for
 alias expansion:  it is still possible to declare any of them as an alias,
-but the alias will never be expanded.  Reserved words are
-tt(!),
-tt([[),
-tt({),
-tt(}),
-tt(case),
-tt(coproc),
-tt(do),
-tt(done),
-tt(elif),
-tt(else),
-tt(end),
-tt(esac),
-tt(fi),
-tt(for),
-tt(foreach),
-tt(function),
-tt(if),
-tt(nocorrect),
-tt(repeat),
-tt(select),
-tt(then),
-tt(time),
-tt(until),
-tt(while).
+but the alias will never be expanded.  Reserved words are described in
+ifnzman(noderef(Reserved Words))\
+ifzman(the section RESERVED WORDS in zmanref(zshmisc)).
 
 Alias expansion takes place while text is being read; hence when this
 option is set it does not take effect until the end of any function or

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-03 17:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-25  0:17 zsh regards reserved word as candidate for alias substitution Vincent Lefevre
2009-03-03 17:23 ` Peter Stephenson
2009-03-03 17:33   ` Peter Stephenson

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).