From nobody@FreeBSD.org  Wed Feb 23 18:54:41 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 3757F106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 23 Feb 2011 18:54:41 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 0CE3E8FC18
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 23 Feb 2011 18:54:41 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p1NIsegK080163
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 23 Feb 2011 18:54:40 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p1NIsewk080159;
	Wed, 23 Feb 2011 18:54:40 GMT
	(envelope-from nobody)
Message-Id: <201102231854.p1NIsewk080159@red.freebsd.org>
Date: Wed, 23 Feb 2011 18:54:40 GMT
From: Bjartur Thorlacius <svartman95@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: head returns EXIT_SUCCESS upon EOF
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         154983
>Category:       bin
>Synopsis:       head(1) returns EXIT_SUCCESS upon EOF
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 23 19:00:19 UTC 2011
>Closed-Date:    Wed Feb 23 21:24:52 UTC 2011
>Last-Modified:  Wed Feb 23 21:24:52 UTC 2011
>Originator:     Bjartur Thorlacius
>Release:        Darwin 8.11.1
>Organization:
>Environment:
Darwin sophie.lan 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386 i386 i386
>Description:
$(head -n $n) returns EXIT_SUCCESS upon premature end of file.

$(head -n $n) should only ever return EXIT_SUCCESS when $n lines have successfully been read to stdout.

P.S. Also affects GNU head.
>How-To-Repeat:
echo|
head -n2 &&
echo bug
>Fix:


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: arundel 
State-Changed-When: Wed Feb 23 21:22:24 UTC 2011 
State-Changed-Why:  
I'm afraid your assumption is wrong. The POSIX specs [1] clearly state that 

"When a file contains less than number lines, it shall be copied 
to standard output in its entirety. This shall not be an error." 

[1] http://pubs.opengroup.org/onlinepubs/9699919799/ 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154983 
>Unformatted:
