From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Mon, 20 Nov 2006 10:45:02 +0100 From: Martin Neubauer To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] echo -n Message-ID: <20061120094502.GA23572@shodan.homeunix.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i Topicbox-Message-UUID: e25234ee-ead1-11e9-9d60-3106f5b1d025 * arisawa@ar.aichi-u.ac.jp (arisawa@ar.aichi-u.ac.jp) wrote: > Hello, > > I have a question: > echo -n > writes 0 length byte to stdout. > Is this intentional specification? > > If it is, what is intended for the specification? Hello, As I see it, echo copies its arguments to stdout, followed by a newline. The `-n' option suppresses this newline. Without looking at the source, it seems echo initiates the write, writes the arguments (if any), writes a newline (if not disabled), and ends the write resulting in a zero-length write for `echo -n'. It could probably be possible to change echo to only do the write if there is anything to output, but I'm not aware of any formal specification of that case. Also, there might be scripts that rely on exactly that behaviour. Maybe a shell function checking the arguments before calling echo would be a cleaner solution. Martin