From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: "var=value exec > file" ignores the assignment?
Date: Wed, 8 Apr 2015 00:51:00 +0900 [thread overview]
Message-ID: <3D84EC4C-3267-4567-8642-B4F86AB93610@kba.biglobe.ne.jp> (raw)
If 'exec' has no command arg but has both parameter assignment
and redirection, the assignment seems to be ignored.
The following script outputs "x = 0" into test.log:
#!/usr/local/bin/zsh
setopt POSIX_BUILTINS
x=0
x=1 exec > test.log
echo "x = $x"
'ksh' and 'bash -posix' (or /bin/sh) output "x = 1", which I
guess what POSIX requires.
Moreover, assuming there is no command named 'junk',
x=$(junk) exec > test.log
does NOT issue "command not found: junk" error.
The following patch *seems* to fix these, but I believe this
is at most a partial fix (or regression at the worst).
Either with or without the patch, and either POSIX_BUILTINS is
set or unset, the following outputs "x = 1" (/bin/sh outputs
"x = 0"). But I don't know whether this need be fixed (or how
to fix it if it need be).
x=0
true | x=1 exec | true
echo "x = $x"
diff --git a/Src/exec.c b/Src/exec.c
index 1a6149a..fdb2470 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3305,6 +3305,13 @@ execcmd(Estate state, int input, int output, int how, int last1)
closemn(mfds, i, REDIR_CLOSE);
if (nullexec) {
+ /*
+ * If nullexec is 2, we have variables to add with the redirections
+ * in place.
+ */
+ if (varspc)
+ addvars(state, varspc, 0);
+ lastval = errflag ? errflag : cmdoutval;
if (nullexec == 1) {
/*
* If nullexec is 1 we specifically *don't* restore the original
@@ -3315,13 +3322,6 @@ execcmd(Estate state, int input, int output, int how, int last1)
zclose(save[i]);
goto done;
}
- /*
- * If nullexec is 2, we have variables to add with the redirections
- * in place.
- */
- if (varspc)
- addvars(state, varspc, 0);
- lastval = errflag ? errflag : cmdoutval;
if (isset(XTRACE)) {
fputc('\n', xtrerr);
fflush(xtrerr);
next reply other threads:[~2015-04-07 15:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-07 15:51 Jun T. [this message]
2015-04-08 17:13 ` Bart Schaefer
2015-04-09 16:13 ` Jun T.
2015-04-15 19:52 ` Peter Stephenson
2015-04-15 20:27 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3D84EC4C-3267-4567-8642-B4F86AB93610@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).