zsh-workers
 help / color / mirror / code / Atom feed
* $@ bug
@ 1995-06-30 22:30 Zefram
  1995-07-03 11:21 ` P.Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Zefram @ 1995-06-30 22:30 UTC (permalink / raw)
  To: Z Shell workers mailing list

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

What's going on?

 -zefram

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQBVAgUBL/R65WWJ8JfKi+e9AQHtdAH+IrpL6uRelS27UuiakCJvy8y60IvRrFDL
w93pzRGyvt6OKFd3GmPTWajummP28VdYdh+IVanL7k0H086DFg8Qcw==
=rmog
-----END PGP SIGNATURE-----


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

* Re: $@ bug
  1995-06-30 22:30 $@ bug Zefram
@ 1995-07-03 11:21 ` P.Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: P.Stephenson @ 1995-07-03 11:21 UTC (permalink / raw)
  To: Zsh hackers list

A.Main@dcs.warwick.ac.uk 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@swansea.ac.uk>  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.


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

end of thread, other threads:[~1995-07-03 11:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-06-30 22:30 $@ bug Zefram
1995-07-03 11:21 ` P.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).