zsh-workers
 help / color / mirror / code / Atom feed
* $(nooutput) problem
@ 1996-05-28  9:18 Peter Stephenson
  1996-05-28 11:34 ` Zoltan Hidvegi
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 1996-05-28  9:18 UTC (permalink / raw)
  To: Zsh hackers list

It seems care is needed: (1) if a command is not a simple one no
arguments may be necessary, so that having no arguments in execcmd()
is perfectly legal; (2) single word substitution needs to keeps its
arguments, for example the variable assignment code expects something
back from prefork(); (3) there's another bug/incompatibility (nearer
the latter than the former) resulting from the failure to delete empty
arguments:

% ksh -c 'cmd=; $cmd print foo'
foo
% zsh -fc 'cmd=; $cmd print foo'
zsh: permission denied: print

(which is certainly not the right answer in any case).

For these reasons I've fixed the problem by getting prefork() to junk
empty nodes if and only if it is not doing single word substitution,
and execcmd() to return if and only if it is a `simple' command with
no arguments.

*** Src/exec.c.empty	Fri May 17 16:25:20 1996
--- Src/exec.c	Tue May 28 10:35:36 1996
***************
*** 1200,1205 ****
--- 1200,1208 ----
      /* Do prefork substitutions */
      prefork(args, (((type == CCASE) ? 4 : 0) | (assign ? 2 : isset(MAGICEQUALSUBST))));
  
+     if (type == SIMPLE && empty(args))
+ 	return;
+ 
      /* Set up special parameter $_ */
      zsfree(underscore);
      if (nonempty(args) && (underscore = ztrdup((char *) getdata(lastnode(args)))))
*** Src/subst.c.empty	Tue May 28 10:34:04 1996
--- Src/subst.c	Tue May 28 10:41:15 1996
***************
*** 51,57 ****
  void
  prefork(LinkList list, int flags)
  {
!     LinkNode node;
  
      for (node = firstnode(list); node; incnode(node)) {
  	char *str, *str3;
--- 51,57 ----
  void
  prefork(LinkList list, int flags)
  {
!     LinkNode node, next;
  
      for (node = firstnode(list); node; incnode(node)) {
  	char *str, *str3;
***************
*** 69,77 ****
  	else if (!(node = stringsubst(list, node, flags & 4)))
  	    return;
      }
!     for (node = firstnode(list); node; incnode(node)) {
  	if (*(char *)getdata(node))
  	    remnulargs(getdata(node));
  	if (unset(IGNOREBRACES) && !(flags & 4))
  	    while (hasbraces(getdata(node)))
  		xpandbraces(list, &node);
--- 69,82 ----
  	else if (!(node = stringsubst(list, node, flags & 4)))
  	    return;
      }
!     for (node = firstnode(list); node; node = next) {
! 	next = nextnode(node);
  	if (*(char *)getdata(node))
  	    remnulargs(getdata(node));
+ 	else if (!(flags & 4)) {
+ 	    uremnode(list, node);
+ 	    continue;
+ 	}
  	if (unset(IGNOREBRACES) && !(flags & 4))
  	    while (hasbraces(getdata(node)))
  		xpandbraces(list, &node);


-- 
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] 7+ messages in thread

end of thread, other threads:[~1996-05-30 19:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-28  9:18 $(nooutput) problem Peter Stephenson
1996-05-28 11:34 ` Zoltan Hidvegi
1996-05-30 16:58   ` execcmd() reordering Peter Stephenson
1996-05-30 18:00     ` Zoltan Hidvegi
1996-05-30 18:26       ` Barton E. Schaefer
1996-05-30 18:46         ` Zoltan Hidvegi
1996-05-30 18:41       ` Zoltan Hidvegi

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