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

Re: $@ bug



A.Main@xxxxxxxxxxxxxxxxx wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> 
> ~/tmp> fn () { $@ }
> ~/tmp> fn echo wibble
> wibble
> ~/tmp> fn
> ~> cd tmp
> ~/tmp> fn () { echo $@ }
> ~/tmp> fn
> 
> ~/tmp>
> 
> 
> (i.e., the function does a "cd" when executing an empty $@.)

The behaviour was actually inconsistent between empty arrays ("no
command") or other empty variables (did nothing).

This seems to fix it without changing too much.  It means another test
in execcmd(), but that's unavoidable in the circumstances.  (If
anybody can think of another reason why the argument list should be
empty at this point I'll stick in another test, but as far as I can
tell, this is O.K.)

*** Src/exec.c.empty	Fri Jun 30 23:06:14 1995
--- Src/exec.c	Mon Jul  3 12:09:42 1995
***************
*** 1120,1129 ****
  		   | (assign ? 02 : isset(MAGICEQUALSUBST))));
  
      zsfree(underscore);
!     if (full(args) && (underscore = ztrdup((char *) getdata(lastnode(args)))))
! 	untokenize(underscore); 
!     else
    	underscore = ztrdup("");
  
      /* warn about "rm *" */
      if (unset(RMSTARSILENT) && interact && isset(SHINSTDIN) &&
--- 1120,1141 ----
  		   | (assign ? 02 : isset(MAGICEQUALSUBST))));
  
      zsfree(underscore);
!     if (full(args)) {
! 	if ((underscore = ztrdup((char *) getdata(lastnode(args)))))
! 	    untokenize(underscore); 
!     } else {
    	underscore = ztrdup("");
+ 	if (type == SIMPLE && !nullexec) {
+ 	    /*
+ 	     * No command found after expansion.  This forces the shell
+ 	     * to run an empty list in the current shell.
+ 	     * Note that variables never get put into the environment
+ 	     * (for e.g. `foo=bar $@' where $@ is empty), but this is
+ 	     * what we want in this case.
+ 	     */
+ 	    type = CURSH;
+ 	}
+     }
  
      /* warn about "rm *" */
      if (unset(RMSTARSILENT) && interact && isset(SHINSTDIN) &&

-- 
Peter Stephenson <P.Stephenson@xxxxxxxxxxxxx>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.



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