From: cherry <lunaria21@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: [9fans] echo -n and zero-length write(2)
Date: Thu, 23 Jan 2014 22:27:42 -0500 [thread overview]
Message-ID: <CACzOosDi7uK-JPvTcdN3So9VzhkjmfvBto0YwUTkdWka41r65Q@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]
Hello Fans,
When echo(1) is invoked with -n and no or empty arguments, it calls
write(2) with zero length. When writing to a pipe, the other end of the
pipe read()'s zero byte, which causes it thinks it's got to the end and
close the pipe, and commands after the "echo -n" would fail to write. I
start thinking whether this is the desired behavior. On one hand, it is an
easy way to do a zero-length write() through echo -n, also it is consistent
for echo(1): to do a write(2). On the other hand, it makes rc script
behaves differently if sending to a pipe, and probably some people would
expect empty echo -n is just a no-op. Which should be better?
The context is, as posted on the werc list, it's template.awk generates rc
script with echo -n, and the output of the script is sent to a pipe. When
the argument is empty it fails. My last post was wrapping echo as
fn echo { builtin echo $* | cat }
But invoking cat for every echo hurts the performance. Perhaps the most
efficient way is to write an ad hoc echo that does not do zero-length
write(2)? Any suggestion?
Thanks,
- cherry
[-- Attachment #2: Type: text/html, Size: 1189 bytes --]
next reply other threads:[~2014-01-24 3:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-24 3:27 cherry [this message]
2014-01-24 4:10 ` Anthony Sorace
2014-01-25 5:12 ` cherry
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=CACzOosDi7uK-JPvTcdN3So9VzhkjmfvBto0YwUTkdWka41r65Q@mail.gmail.com \
--to=lunaria21@gmail.com \
--cc=9fans@9fans.net \
/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.
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).