GNU bug report logs - #19240
cut 8.22 adds newline

Previous Next

Package: coreutils;

Reported by: John Kendall <john <at> capps.com>

Date: Mon, 1 Dec 2014 16:44:01 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Eric Blake <eblake <at> redhat.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#19240: closed (cut 8.22 adds newline)
Date: Mon, 01 Dec 2014 17:06:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 01 Dec 2014 10:05:37 -0700
with message-id <547C9FE1.2020702 <at> redhat.com>
and subject line Re: bug#19240: cut 8.22 adds newline
has caused the debbugs.gnu.org bug report #19240,
regarding cut 8.22 adds newline
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
19240: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19240
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: John Kendall <john <at> capps.com>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: cut 8.22 adds newline
Date: Mon, 1 Dec 2014 13:39:38 +0000
Hi,

I don't know if this is a bug, but I wonder if there is a consensus on correct behavior.
The solaris version of cut does not add a newline if there was no newline on the input:

Consider this printf command:

$ printf "1\n12\n123\n1234\n12345\n123456"
1
12
123
1234
12345
123456$

Note that the shell prompt appears after the 6 on the last line.


# Solaris cut
$ printf "1\n12\n123\n1234\n12345\n123456" | cut -c1-4
1
12
123
1234
1234
1234$

Note that the shell prompt appears after the 4 on the last line.

#gnu 8.22 cut
/$ printf "1\n12\n123\n1234\n12345\n123456" | cut -c1-4
1
12
123
1234
1234
1234
$

Note that the shell prompt appears on its own line.

I came upon this while porting scripts from Solaris 10 to Centos 7.

Interested to hear you thoughts.

Thanks and best regards,
John
---
John Kendall
System Administrator
CAI International



[Message part 3 (message/rfc822, inline)]
From: Eric Blake <eblake <at> redhat.com>
To: John Kendall <john <at> capps.com>, 19240-done <at> debbugs.gnu.org
Subject: Re: bug#19240: cut 8.22 adds newline
Date: Mon, 01 Dec 2014 10:05:37 -0700
[Message part 4 (text/plain, inline)]
tag 19240 notabug
thanks

On 12/01/2014 06:39 AM, John Kendall wrote:
> Hi,
> 
> I don't know if this is a bug, but I wonder if there is a consensus on correct behavior.
> The solaris version of cut does not add a newline if there was no newline on the input:

Such an input is not a text file (the POSIX definition of text file
requires that if the file is not empty, it ends in newline); and POSIX
leaves the behavior of 'cut' unspecified if it is not operating on a
text file.

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_397

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html

Therefore, it is unspecified whether cut will add or skip a trailing
newline.

> 
> I came upon this while porting scripts from Solaris 10 to Centos 7.

GNU chose to make cut behave similarly to sort, which IS required to add
a trailing newline even when the input lacks one (that is, POSIX goes
the extra mile and defines sort behavior on non-text files that are
non-text only because they lack a newline).  Solaris chose differently.
 But the problem is that you are relying on unspecified behavior; fix
your input files to have a trailing newline, then you won't have to
worry about it.

At any rate, I see no reason to change GNU behavior, so I'm closing this
as not a bug.  Feel free to add further comments, though, including if
you have a stronger argument for why we should reopen the bug and change
behavior.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 10 years and 172 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.