* PATCH: pws-25: parameter assignment with redirection
@ 1999-07-05 14:41 Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 1999-07-05 14:41 UTC (permalink / raw)
To: Zsh hackers list
This
foo=bar >&/dev/null
is interpreted as a redirection which uses $NULLCMD to write to /dev/null.
I would interpret it as a parameter assigment with the output redirected so
that error messages about bad patterns and so forth don't appear. This
patch does that.
--- Src/exec.c.av Mon Jul 5 13:16:12 1999
+++ Src/exec.c Mon Jul 5 16:38:12 1999
@@ -1532,6 +1532,9 @@
/* Was this "exec < foobar"? */
nullexec = 1;
break;
+ } else if (vars && nonempty(vars)) {
+ nullexec = 2;
+ break;
} else if (!nullcmd || !*nullcmd ||
(cflags & BINF_PREFIX)) {
zerr("redirection with no command", NULL, 0);
@@ -1871,7 +1874,8 @@
addfd(forked, save, mfds, fn->fd1, fil, 0);
/* If this is 'exec < file', read from stdin, *
* not terminal, unless `file' is a terminal. */
- if (nullexec && fn->fd1 == 0 && isset(SHINSTDIN) && interact)
+ if (nullexec == 1 && fn->fd1 == 0 &&
+ isset(SHINSTDIN) && interact)
init_io();
break;
case CLOSE:
@@ -1931,17 +1935,28 @@
closemn(mfds, i);
if (nullexec) {
- for (i = 0; i < 10; i++)
- if (save[i] != -2)
- zclose(save[i]);
+ if (nullexec == 1) {
+ /*
+ * If nullexec is 1 we specifically *don't* restore the original
+ * fd's before returning.
+ */
+ for (i = 0; i < 10; i++)
+ if (save[i] != -2)
+ zclose(save[i]);
+ return;
+ }
/*
- * Here we specifically *don't* restore the original fd's
- * before returning.
+ * If nullexec is 2, we have variables to add with the redirections
+ * in place.
*/
- return;
- }
-
- if (isset(EXECOPT) && !errflag) {
+ if (vars)
+ addvars(vars, 0);
+ lastval = errflag ? errflag : cmdoutval;
+ if (isset(XTRACE)) {
+ fputc('\n', stderr);
+ fflush(stderr);
+ }
+ } else if (isset(EXECOPT) && !errflag) {
/*
* We delay the entersubsh() to here when we are exec'ing
* the current shell (including a fake exec to run a builtin then
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1999-07-05 15:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-05 14:41 PATCH: pws-25: parameter assignment with redirection 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).