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