From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Mon, 20 Nov 2006 07:46:12 -0500 From: "Russ Cox" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu> Subject: Re: [9fans] echo -n In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: Topicbox-Message-UUID: e2578d22-ead1-11e9-9d60-3106f5b1d025 > I have a question: > echo -n > writes 0 length byte to stdout. > Is this intentional specification? Yes. > If it is, what is intended for the specification? A zero-length write. > Output to pipe by a rc script such as > echo -n $foo > can close the pipe if $foo is empty. No, it doesn't close the pipe. It sends a zero-length message, causing the reader to get a zero-length message returned from read. The pipe is still completely usable; the problem is that the reader interprets this zero return as EOF, as is the convention. It's too bad that both of these conditions are signaled the same way, but the pipe is *not* closed. There are two options available for dealing with this: change your writer not to write empty messages (as you have), or change the reader to ignore them. For the latter, just ignore a return value of 0 and read again. If the pipe is really closed, then after returning 0 three times, read will start returning -1. Russ