zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list),
	Daniel Dignam <daniel@UG.EDS.COM>
Subject: Re: set -vx changes output of subshells
Date: Wed, 05 Feb 1997 16:06:26 +0100	[thread overview]
Message-ID: <199702051506.QAA08836@hydra.ifh.de> (raw)
In-Reply-To: "Daniel Dignam"'s message of "Tue, 28 Jan 1997 08:37:32 MET." <32EDBACC.41C6@UG.EDS.COM>

Daniel Dignam wrote:
> Hi Folks,
> 
>   I've just built zsh 3.1.1 and have found a problem with redirection in
> subshells and set -vx. It appears to be adding a return at the start of
> the output (this makes debugging a trifle hard):
> 
> alfep3% set -vx
> alfep3% a=$(ls foo 2>&1)
> a=$(ls foo 2>&1)
> + a=+ a=+ ls foo
> foo 
> alfep3% echo $a | wc -l
> echo $a | wc -l
> + echo + a=+ ls foo
> foo
> + wc -l
>          2

I got a chance to think about this (didn't notice any other replies)
and it's not really clear to me it's a bug.  (Sorry, I know that
answer grates on the nerves.)  You've told zsh to send a message of
what it's doing to stderr, then you've redirected stderr from $(...)
to the output... naturally the xtrace output goes to the variable so
that a contains an initial line `+ a=+ ls -F -l zsh'.  

Ksh does something different: looking at the output, it seems to be
because the 2>&1 doesn't get processed till last, but I can't see a
good reason why the shell should *have* to do that.  It could probably
be moved further up in zsh, removing the doubled xtrace code for
builtins and external commands, though it looks like the addvars()
part would still have to be separate.  This would presumably fix this
problem.

There are certainly still minor problems with set -x, though: for
example, the 2>&1 doesn't appear at all.  Probably something needs to
be added to addfd().

I noticed one other thing with the option handling: the EXECOPT
option, properly the noexec option except it's negated, seems to be
doing rather to much work: it does all the forking and I/O redirection
even though it doesn't actually execute the commands.  So, for
example, a script containing:

print this is a file >shfile
set -n
print this is no longer a file >shfile

in ksh will leave shfile containing `this is a file', in zsh will
leave an empty shfile, since the redirection has been done for the
second print even though the command wasn't executed.

This is presumably wrong, but how little should noexec be doing?  Can
we omit the fork in execcmd()?  Should the glob then be done without a
fork even if the command not to be executed had a & after it?

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


  reply	other threads:[~1997-02-05 15:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-28  8:37 Daniel Dignam
1997-02-05 15:06 ` Peter Stephenson [this message]
1997-02-05 15:32   ` Daniel Dignam
1997-02-09 22:45     ` ((Re: set -vx changes output of)) subshells C. v. Stuckrad
1997-02-10  2:21       ` Bart Schaefer

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=199702051506.QAA08836@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=daniel@UG.EDS.COM \
    --cc=zsh-workers@math.gatech.edu \
    /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).