zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: subtle `echo' bug
Date: Wed, 15 Jun 2005 08:17:26 +0000	[thread overview]
Message-ID: <1050615081726.ZM7939@candle.brasslantern.com> (raw)
In-Reply-To: <20050615074851.GQ4685@solemn.turbinal.org>

On Jun 15, 11:48am, Alexey Tourbin wrote:
> Subject: Re: subtle `echo' bug
>
> On Wed, Jun 15, 2005 at 12:28:44AM +0000, Bart Schaefer wrote:
> > In short, if you write nonsense code, you get nonsense results.  Don't
> > try to feed input to a command that doesn't want it.
> 
> It was quite a real command!

I don't doubt that.  The point is that " ... | echo" is nonsense, no
matter what good reason you may have had for attempting it, because
that's writing on the standard input of a command that does not read
from standard input.

In other words, even with " ... | /bin/echo" in your example here:

>       ... {
> 	echo "$v1 has problems with $v2..." |fmt; grep -w $v2 list; } |
> 	/bin/echo ...

If "grep -w $v2 list" generates a sufficient volume of output, the pipe
on /bin/echo's stdin can fill up and the command may fail.  It's not a
zsh problem, it's a fundamental problem with the nature of unix pipes
and the way you're using them.

Zsh happens to make the problem show up sooner because the first echo
gets a write error when the second echo fails to read; but that's not
a bug, unless echo is somehow required never to fail on write error.

> I used "echo" as a comment to find out and check twice the commands that
> were going to be executed.

The right thing would be something like this, which reads and throws
away its input:

    { ... } | { cat > /dev/null; echo /path/to/my/script ... }

You could make a function:

    notreally() {
       [[ -t 0 ]] || cat > /dev/null
       print -R "$@"
    }

And then

    ... | notreally /path/to/my/script ...

Or, better still, since your script is parsing command line options,
add an option to it that tells it to run without doing its destructive
thing, so that you don't have to wrap it in another command to test it.

    ... | /path/to/my/script --notreally --opt...


  reply	other threads:[~2005-06-15  8:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-14 17:27 Alexey Tourbin
2005-06-14 18:12 ` Andrey Borzenkov
2005-06-14 18:49   ` Alexey Tourbin
2005-06-15  0:28   ` Bart Schaefer
2005-06-15  7:48     ` Alexey Tourbin
2005-06-15  8:17       ` Bart Schaefer [this message]
2005-06-15  9:10     ` Peter Stephenson
2005-06-15 13:56       ` Peter Stephenson
2005-06-15 15:32         ` Bart Schaefer
2005-06-15 15:49           ` Peter Stephenson
2005-06-15 16:39             ` Bart Schaefer
2005-06-15 16:47               ` Peter Stephenson
2005-06-27 10:03               ` Peter Stephenson
2005-06-27 14:31                 ` Bart Schaefer
2005-06-27 14:44                   ` 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=1050615081726.ZM7939@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /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).