Subject: Re: bug#7915: Possible off-by-1 in wc

From: Eric Blake <[email-masked]>
Date: Tue, 25 Jan 2011 19:08:15 -0700

[Let's keep the list in the loop]

On 01/25/2011 07:04 PM, Sune Mølgaard wrote:
>> Thanks for the report.  However, this is not a bug - echo is outputting
>> a newline (which is a second character, and third byte given the
>> encoding of your chosen character).
>>
>> To see the difference, try:
>>
>> $ echo Å | od -tx1z
>> $ printf Å | od -tx1z
> 
> Thanks for the swift reply - I figured it might be something like that,
> but would it be possible to make an option to strip things like that, or
> is that a silly question?

An option to which program, echo or wc?

For wc, it's not possible.  How is wc supposed to know whether the input
has an extra trailing newline that should be ignored?  Fix the input
side of the equation, rather than adding complexity to wc.

For echo, the option is already (non-portably) there, in the form of
'echo -n' (won't work everywhere), or portably by using printf instead
of echo (as was the case in my example).

-- 
Eric Blake   [email-masked]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org