* [9fans] echo -n and zero-length write(2)
@ 2014-01-24 3:27 cherry
2014-01-24 4:10 ` Anthony Sorace
0 siblings, 1 reply; 3+ messages in thread
From: cherry @ 2014-01-24 3:27 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] echo -n and zero-length write(2)
2014-01-24 3:27 [9fans] echo -n and zero-length write(2) cherry
@ 2014-01-24 4:10 ` Anthony Sorace
2014-01-25 5:12 ` cherry
0 siblings, 1 reply; 3+ messages in thread
From: Anthony Sorace @ 2014-01-24 4:10 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 445 bytes --]
> Any suggestion?
There is no "better" answer to this question. You are advised to
read "The Unix and the Echo"[1], by Doug McIlroy, and Russ Cox's
adaptation for our system, "The Plan 9 and the Echo"[2].
If you need different behavior than what's there, you want
something other than echo.
[1] http://everything2.com/title/The+UNIX+and+the+Echo)
[2] https://groups.google.com/forum/#!msg/comp.os.plan9/Bg-gyAzbWiE/VZj7qSVn5uIJ
[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 169 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] echo -n and zero-length write(2)
2014-01-24 4:10 ` Anthony Sorace
@ 2014-01-25 5:12 ` cherry
0 siblings, 0 replies; 3+ messages in thread
From: cherry @ 2014-01-25 5:12 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
[-- Attachment #1: Type: text/plain, Size: 360 bytes --]
On Thu, Jan 23, 2014 at 11:10 PM, Anthony Sorace <a@9srv.net> wrote:
> > Any suggestion?
>
> There is no "better" answer to this question. You are advised to
> read "The Unix and the Echo"[1], by Doug McIlroy, and Russ Cox's
> adaptation for our system, "The Plan 9 and the Echo"[2].
>
Thanks for pointing me to the right direction :)
- cherry
[-- Attachment #2: Type: text/html, Size: 718 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-25 5:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-24 3:27 [9fans] echo -n and zero-length write(2) cherry
2014-01-24 4:10 ` Anthony Sorace
2014-01-25 5:12 ` cherry
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).