zsh-workers
 help / color / mirror / code / Atom feed
* Problematic change in alias behavior in pre3
@ 1996-07-21 17:41 Bart Schaefer
  1996-07-21 18:51 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1996-07-21 17:41 UTC (permalink / raw)
  To: zsh-workers

Here's zsh 3.0-pre2:

zsh% alias show="noglob show"
zsh% function show() { show=(); show=( $~* ); print -rc $show }
zsh% show **/Make*
Doc/Makefile              Makefile                  StartupFiles/Makefile
Doc/Makefile.in           Makefile.in               StartupFiles/Makefile.in
Etc/Makefile              Misc/Makefile             Util/Makefile
Etc/Makefile.in           Misc/Makefile.in          Util/Makefile.in
Functions/Makefile        Src/Makefile
Functions/Makefile.in     Src/Makefile.in

(The point here is to set $show to the result of the glob only if the glob
succeeds, and otherwise to set it to empty.  I use cshnullglob.)

Here's pre3:

zsh% alias show="noglob show"
zsh% function show() { show=(); show=( $~* ); print -rc $show }
zsh: parse error near `)'
zsh% show=()
zsh: parse error near `)'
zsh% unalias show
zsh% function show() { show=(); show=( $~* ); print -rc $show }
zsh% 

Why does the existence of the alias mess up the variable assignment?

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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

* Re: Problematic change in alias behavior in pre3
  1996-07-21 17:41 Problematic change in alias behavior in pre3 Bart Schaefer
@ 1996-07-21 18:51 ` Bart Schaefer
  1996-07-22 10:03   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1996-07-21 18:51 UTC (permalink / raw)
  To: zsh-workers

On Jul 21, 10:41am, Bart Schaefer wrote:
} Subject: Problematic change in alias behavior in pre3
}
} zsh% alias show="noglob show"
} zsh% show=()
} zsh: parse error near `)'
} 
} Why does the existence of the alias mess up the variable assignment?

I don't know how/why this worked in pre2, but in pre3 gettokstr() returns
"show=stuff" for ENVSTRING, but only "show" for ENVARRAY.  Thus the token
"show" is incmdpos when when exalias(), and thus is subject to expansion.

It's not sufficient to assign incmdpos=0 when ENVARRAY, because then this
kind of thing fails:

zsh% alias foo='echo help'
zsh% show=(stuff) foo bar
zsh: command not found: foo

So here's what I came up with; I return tokstr "show=" from the lexer for
ENVARRAY, and then strip off the '=' when parsing, as is done for ENVSTRING.
It's impossible to create an alias name containing an '=' (maybe that's a
bug, too?) so exalias() can't possibly succeed on "show=".

*** Src/lex.c.0	Thu Jul 18 19:15:13 1996
--- Src/lex.c	Sun Jul 21 11:26:22 1996
***************
*** 853,858 ****
--- 853,859 ----
  		       incmdpos && !bct && !brct) {
  		e = hgetc();
  		if (e == '(' && incmdpos) {
+ 		    add('=');
  		    *bptr = '\0';
  		    return ENVARRAY;
  		}
*** Src/parse.c.0	Fri Jul 19 11:17:12 1996
--- Src/parse.c	Sun Jul 21 11:29:49 1996
***************
*** 916,922 ****
  
  	    v->type = PM_ARRAY;
  	    incmdpos = 0;
! 	    v->name = tokstr;
  	    cmdpush(CS_ARRAY);
  	    yylex();
  	    v->arr = par_nl_wordlist();
--- 916,922 ----
  
  	    v->type = PM_ARRAY;
  	    incmdpos = 0;
! 	    equalsplit(v->name = tokstr, &v->str);
  	    cmdpush(CS_ARRAY);
  	    yylex();
  	    v->arr = par_nl_wordlist();

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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

* Re: Problematic change in alias behavior in pre3
  1996-07-21 18:51 ` Bart Schaefer
@ 1996-07-22 10:03   ` Peter Stephenson
  1996-07-22 14:33     ` Zefram
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 1996-07-22 10:03 UTC (permalink / raw)
  To: Zsh hackers list

schaefer@candle.brasslantern.com wrote:
> It's not sufficient to assign incmdpos=0 when ENVARRAY, because then this
> kind of thing fails:
> 
> zsh% alias foo='echo help'
> zsh% show=(stuff) foo bar
> zsh: command not found: foo

No objection to the fix, but is it clear this is kind of thing is
useful anyway?  Arrays don't seem to get exported in this fashion, not
even space-concatenated.

% show=stuff zsh -c 'printenv show'
stuff
% show=(stuff) zsh -c 'printenv show'
<zilch>

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



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

* Re: Problematic change in alias behavior in pre3
  1996-07-22 10:03   ` Peter Stephenson
@ 1996-07-22 14:33     ` Zefram
  0 siblings, 0 replies; 4+ messages in thread
From: Zefram @ 1996-07-22 14:33 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

>No objection to the fix, but is it clear this is kind of thing is
>useful anyway?  Arrays don't seem to get exported in this fashion, not
>even space-concatenated.

They can't be exported across an exec.  They *can* be exported to
subshells, shell functions, builtins and so on.

-zefram



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

end of thread, other threads:[~1996-07-22 14:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-21 17:41 Problematic change in alias behavior in pre3 Bart Schaefer
1996-07-21 18:51 ` Bart Schaefer
1996-07-22 10:03   ` Peter Stephenson
1996-07-22 14:33     ` Zefram

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