[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#19240: cut 8.22 adds newline
From: |
Eric Blake |
Subject: |
bug#19240: cut 8.22 adds newline |
Date: |
Thu, 04 Dec 2014 14:48:17 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 |
On 12/04/2014 01:39 PM, Paul Eggert wrote:
> On 12/04/2014 10:41 AM, John Kendall wrote:
>> echo "$FILE ===========================\c"| cut -c1-30
>
> Since you're going to have to rewrite it anyway if you want it to be
> portable, I suggest doing it this way:
>
> printf '%.30s' "$FILE ==========================="
>
> as it's a lot more efficient anyway.
Be careful; the POSIX specification of '%.30s' does NOT work well with
multibyte characters; it is specified as:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html#tag_05
"precision
Gives the minimum number of digits to appear for the d, o, i, u, x,
or X conversion specifiers (the field is padded with leading zeros), the
number of digits to appear after the radix character for the e and f
conversion specifiers, the maximum number of significant digits for the
g conversion specifier; or the maximum number of bytes to be written
from a string in the s conversion specifier. The precision shall take
the form of a <period> ( '.' ) followed by a decimal digit string; a
null digit string is treated as zero."
which means that it CAN and WILL corrupt output if the number of bytes
written falls in the middle of a multi-byte character.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- bug#19240: cut 8.22 adds newline, (continued)
- bug#19240: cut 8.22 adds newline, Eric Blake, 2014/12/01
- bug#19240: cut 8.22 adds newline, Pádraig Brady, 2014/12/01
- bug#19240: cut 8.22 adds newline, Bob Proulx, 2014/12/04
- bug#19240: cut 8.22 adds newline, John Kendall, 2014/12/04
- bug#19240: cut 8.22 adds newline, Paul Eggert, 2014/12/04
- bug#19240: cut 8.22 adds newline, John Kendall, 2014/12/04
- bug#19240: cut 8.22 adds newline, Eric Blake, 2014/12/04
- bug#19240: cut 8.22 adds newline, Eric Blake, 2014/12/04
- bug#19240: cut 8.22 adds newline, John Kendall, 2014/12/04
- bug#19240: cut 8.22 adds newline, Bob Proulx, 2014/12/04
- bug#19240: cut 8.22 adds newline,
Eric Blake <=
- bug#19240: cut 8.22 adds newline, Bob Proulx, 2014/12/04
- bug#19240: cut 8.22 adds newline, Bob Proulx, 2014/12/04
- bug#19240: cut 8.22 adds newline, Eric Blake, 2014/12/04
- bug#19240: cut 8.22 adds newline, Bob Proulx, 2014/12/04