From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 05 15:33:21 2018 Received: (at submit) by debbugs.gnu.org; 5 Nov 2018 20:33:22 +0000 Received: from localhost ([127.0.0.1]:35685 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gJlYm-0002TH-41 for submit@debbugs.gnu.org; Mon, 05 Nov 2018 15:33:20 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36566) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gJlWN-0002PR-Na for submit@debbugs.gnu.org; Mon, 05 Nov 2018 15:30:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJlWH-0003Cb-QG for submit@debbugs.gnu.org; Mon, 05 Nov 2018 15:30:46 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,FREEMAIL_FROM, HTML_MESSAGE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:53599) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJlWH-0003CT-M5 for submit@debbugs.gnu.org; Mon, 05 Nov 2018 15:30:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJlWG-0004R6-SK for bug-coreutils@gnu.org; Mon, 05 Nov 2018 15:30:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJlWG-0003Bb-3g for bug-coreutils@gnu.org; Mon, 05 Nov 2018 15:30:44 -0500 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]:32927) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gJlWF-00034o-SH for bug-coreutils@gnu.org; Mon, 05 Nov 2018 15:30:44 -0500 Received: by mail-io1-xd2c.google.com with SMTP id f12-v6so7570073iog.0 for ; Mon, 05 Nov 2018 12:30:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=MJl5UYcOTFI9zr+Q+0CkKxnGJzEK9SxjuD6a0CEcBXQ=; b=awBXigmiXhisbe0os47igR3VMctXbI0udzeWLBkUr1tqMqerNQREMQe6x4qMRLYZcr xRyB7A2TxRcm07Zd4x4Y3ApQEFEkZ7pT6vD4DXPAgyXwZXpo/2JCf4bSFk28uxkC4VbT /2XPmuJJiPR1PcKriCAEmQOmgT6+8cuUWFLBX3wZASUU5sMWBTr9/83gKPFtBJt1/0mm /Qt7XrRmnp6YreQTcb8EDpvAqAffMzfSjf8SISrZkFxVzB9GM2F71fQCQSHvobR9Y69P RAc0NWxlbSsuHuCWMfqEeLFE+7K8PssGdSBfoegFLSag8nrtLcD9QsE+Rl9p+ckHG7a/ FMJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=MJl5UYcOTFI9zr+Q+0CkKxnGJzEK9SxjuD6a0CEcBXQ=; b=ccBKSNKo+I8rhxAXWeBySTiybkx+Q0KrFnPwrMnP5JdGO+axOEEgb1QL0NsKWys/5I YdK2eVnx9PRRqxWAqW+YKws+6bl5OzwfPIH1bYLuqFY/v1/KxE93Sp+ZKhH5yL6cOjFE CE6BXSn48ssE7aYu6opTBK4qlsLgCTofwsZzigUBVgEXk6tgbvHD61Q4WmI+fyUfsZoe eHgWLNKiQbqnEalwIrm7pCrOX8WeJmx5sv5M/7UJJv5ZnVnsWtE/3u57Bh2l7qvirQDl ZZWN+FX9bMKJ5Je38qZESx1uFvNCb5M+gFl4sQ+7rgdbBrO5yiE+bzvE+FjAWsc3znec pThw== X-Gm-Message-State: AGRZ1gKHO7A+fmG0H6pJflvX2/XVXhTz94289K7VBxkdCGHnUKzKMr5x cigT2NS4n88gPXHa9//PUlovDrOiIMXxxVKng7QBjA== X-Google-Smtp-Source: AJdET5cxtlJ1Xrfclh+b6wEP1UAm9wc4o1v5x70zZJvIeRMtGl/R7q2aFOTQsGvHxmZQb5d9xctlF1Ln2suP+RGTP7I= X-Received: by 2002:a6b:c84e:: with SMTP id y75-v6mr18942677iof.186.1541449829227; Mon, 05 Nov 2018 12:30:29 -0800 (PST) MIME-Version: 1.0 From: Luiz Angelo Daros de Luca Date: Mon, 5 Nov 2018 18:30:17 -0200 Message-ID: Subject: head does not consume input after '-c' is satisfied To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary="00000000000082a2c10579f0c1d7" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 05 Nov 2018 15:33:18 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --00000000000082a2c10579f0c1d7 Content-Type: text/plain; charset="UTF-8" Hello, Once head read enough bytes to satisfy -c option, it stops reading input and quit. This is different from what -n does and it is also different from both FreeBSD and busybox head implementation. With GNU Coreutils head: $ echo -e "123\n456\n789" | { head -n 1; while read a; do echo "-$a-"; done; } 123 $ echo -e "123\n456\n789" | { head -c 4; while read a; do echo "-$a-"; done; } 123 -456- -789- $ With all other head implementations I tested: $ echo -e "123\n456\n789" | { head -c 4 ; while read a ; do echo "-$a-" ; done ; } 123 $ It would make sense to both -n and -c have the same meaning, differing only whether to read bytes or lines. Regards, -- Luiz Angelo Daros de Luca luizluca@gmail.com --00000000000082a2c10579f0c1d7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

Once head read enough bytes to s= atisfy -c option, it stops reading input and quit.
This is differ= ent from what -n does and it is also different from both FreeBSD and busybo= x head implementation.

With GNU Coreutils head:

$ echo -e "123\n456\n789" | { head -n 1; w= hile read a; do echo "-$a-"; done; }=C2=A0
123
$ echo -e "123\n456\n789" | { head -c 4; while read a; do echo = "-$a-"; done; }=C2=A0
123
-456-
-78= 9-
$

With all other head implementations= I tested:

$ echo -e "123\n456\n789"= ; | { head -c 4 ; while read a ; do echo "-$a-" ; done ; }
<= div>123
$

It would make sense to b= oth -n and -c have the same meaning, differing only whether to read bytes o= r lines.

Regards,
--

Luiz Angelo Daros de Luca
luizluca@gmail.com

--00000000000082a2c10579f0c1d7-- From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 05 16:18:07 2018 Received: (at submit) by debbugs.gnu.org; 5 Nov 2018 21:18:07 +0000 Received: from localhost ([127.0.0.1]:35757 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gJmG5-0003aa-Ld for submit@debbugs.gnu.org; Mon, 05 Nov 2018 16:18:07 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49252) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gJmG4-0003a4-37 for submit@debbugs.gnu.org; Mon, 05 Nov 2018 16:18:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJmFy-0002oo-1c for submit@debbugs.gnu.org; Mon, 05 Nov 2018 16:17:58 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36919) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJmFx-0002nl-Tm for submit@debbugs.gnu.org; Mon, 05 Nov 2018 16:17:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJmFw-0002uQ-TT for bug-coreutils@gnu.org; Mon, 05 Nov 2018 16:17:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJmFs-0002QO-92 for bug-coreutils@gnu.org; Mon, 05 Nov 2018 16:17:56 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:49609) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJmFr-0002IK-Ve for bug-coreutils@gnu.org; Mon, 05 Nov 2018 16:17:52 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5502B22A74 for ; Mon, 5 Nov 2018 16:17:50 -0500 (EST) Received: from web1 ([10.202.2.211]) by compute1.internal (MEProxy); Mon, 05 Nov 2018 16:17:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dimebar.com; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:subject:date:references; s=fm1; bh=Gjp 5ZJKncl/qI7pCjns8CJWqqK1NqM/nztTNVZkDdLs=; b=RR7zaiHGz6W5SGPnG1d mmjaK0vO/i5MCb4c9VSFag0m+pXJbe547XkHFn1A7PfXofWKQUAjirMY/FeWuNfi 4M6pN4PDqIaQQy+Y/9NQC6O9kkSqrXlLi2Agy5Khdxe2vih//vAic8A8Hi4Lavak 9xExL0qHrH83Mtg0nfvKs4YBwUzWpQbUeM1t4dbtHKH0SUsXrSD74UEmdF8a/d61 86yB9lFsdK8V+MX2zLfUHobAD4n8Gaw9lHF0tGR/NdDFO0IVhl8UA/lC+jfaZBD9 XapxoNR4lm+lKNFO1AdvbZQHqQMV6Mm6EfpsEYckUTYBhnn+tOLP2EBhuArV+Z9z K5A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=Gjp5ZJKncl/qI7pCjns8CJWqqK1NqM/nztTNVZkDd Ls=; b=y+s01zkWVVRoePmdv3Ljtpz+giejKZp0GGUmPLmqhhmF/ZK1IsT5IusUg R52fsIGkYa6Ur81bR2WSRUpThF/PnFcIdQad4+9nrDE13IaZ51/R/WgmvRN6Sz+X aC9qg2iER4wnJwEm4qFfZhLIG9VQ0WmfRMfI3hUZwQsgVa+NYku3rWrM2/yWa66i rJKNaBcRbfauirxac3A++cbcbCyiR6/GyfkX6ZX8oWoyY7i2w2H1LBXIyDvr5FWn XLrrFl5kjt7xVJshbzrjMpfoFG+HutYGo/eDh3pjRQSWeSJiF8ROH5tSjw24bSJB GVb+2cPCz61IF3KiiexHgQulq8upA== X-ME-Sender: X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 99) id EF92D9445C; Mon, 5 Nov 2018 16:17:49 -0500 (EST) Message-Id: <1541452669.415505.1566605800.6F507D78@webmail.messagingengine.com> From: Philip Rowlands To: bug-coreutils@gnu.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-d469da0c In-Reply-To: Subject: Re: bug#33281: head does not consume input after '-c' is satisfied Date: Mon, 05 Nov 2018 21:17:49 +0000 References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) On Mon, 5 Nov 2018, at 20:30, Luiz Angelo Daros de Luca wrote: > > Once head read enough bytes to satisfy -c option, it stops reading input > and quit. > This is different from what -n does and it is also different from both > FreeBSD and busybox head implementation. > > With GNU Coreutils head: > > $ echo -e "123\n456\n789" | { head -n 1; while read a; do echo "-$a-"; > done; } > 123 This is incomplete; head doesn't read everything, but more than one line. On my (rather aged Linux) system: $ head --version head (GNU coreutils) 8.25 $ seq 1864 | { head -n 1; while read a; do echo "-$a-"; done; } 1 -- -1861- -1862- -1863- -1864- What's special about 1860 lines of output? It's just over the amount of data which head reads from the pipe, 8192 bytes. $ seq 1860 | wc -c 8193 > $ echo -e "123\n456\n789" | { head -c 4; while read a; do echo "-$a-"; > done; } > 123 > -456- > -789- In this case head knows it only needs 4 bytes, so only reads 4 bytes. > With all other head implementations I tested: > > $ echo -e "123\n456\n789" | { head -c 4 ; while read a ; do echo "-$a-" ; > done ; } > 123 > $ > > It would make sense to both -n and -c have the same meaning, differing only > whether to read bytes or lines. Consistency would be good, but consider in the case of lines, head doesn't know up-front how much data to read. The only way to read exactly the right amount, not a byte more, would be to read one byte at a time, something of a performance killer. It's not possible to "un-read" data you've collected via the read syscall. To achieve consistency in the other direction, head could ignore the optimization to reduce the number of bytes read, and always read 8192 bytes, knowing that some would be discarded. This seems to be more in line with the other implementations you've tried. For consistency's sake, what would these do? For widely differing values, the only way to produce the same residual output would be to consume all input data. $ cat file.txt | { head -n 100; wc -c; } $ cat file.txt | { head -c 100KB; wc -c; } Cheers, Phil From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 06 02:06:50 2018 Received: (at 33281) by debbugs.gnu.org; 6 Nov 2018 07:06:50 +0000 Received: from localhost ([127.0.0.1]:35939 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gJvRq-00037U-Ef for submit@debbugs.gnu.org; Tue, 06 Nov 2018 02:06:50 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:50963) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gJvRo-00037I-BU for 33281@debbugs.gnu.org; Tue, 06 Nov 2018 02:06:48 -0500 Received: from [192.168.101.10] ([91.12.166.119]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N8oOk-1fQX1d1nc6-015pBS; Tue, 06 Nov 2018 08:06:39 +0100 Received: from [192.168.101.10] ([91.12.166.119]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N8oOk-1fQX1d1nc6-015pBS; Tue, 06 Nov 2018 08:06:39 +0100 Subject: Re: bug#33281: head does not consume input after '-c' is satisfied To: Philip Rowlands , 33281@debbugs.gnu.org References: <1541452669.415505.1566605800.6F507D78@webmail.messagingengine.com> From: Bernhard Voelker Openpgp: preference=signencrypt Autocrypt: addr=mail@bernhard-voelker.de; prefer-encrypt=mutual; keydata= xsBNBFPirzMBCACyzYldTjQ4ufFOkByY5Nn5USb5GFoL48nWBwNHjd9KUbtRRNlQiPNKd6hK Gvd3BGi5aoFKA4ytfRk6jbAbW3jVb3R8wYaV08mOy4KVEKxqN4bxsXlMjNChXVR+rtKDmfI+ oPTL+cPH2X6gW4W02IRbVw0uUhNm6zEedC/gNrY/mTlf1enZ46jxZ7BTUZaG+kx38UMISIMB zSzLRtdkwgmHj4jS3p1fF2cwRqLclIfMjKGpbNFPEXeXKWrCLcqHw78795eAR9q0YvrDkfIn GdDBwfb3VM4NdulwIFzvYZMSXvSbbyPLB5YkHU5aAWQHUse4WlfT5ccDpbzUYldRAvF9ABEB AAHNK0Jlcm5oYXJkIFZvZWxrZXIgPG1haWxAYmVybmhhcmQtdm9lbGtlci5kZT7CwHkEEwEC ACMFAlPir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18nWcHALKMU/36Eua/ylalf/2c2YkBp9KCLVmGgPkUgW52EeRPgroIsiwu+rwCSV6Z UyCJ+OymCg== Message-ID: <19eccf29-bc06-ab34-1e70-6ed38ec2e8e4@bernhard-voelker.de> Date: Tue, 6 Nov 2018 08:06:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1541452669.415505.1566605800.6F507D78@webmail.messagingengine.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:z6a8nP/3USkjuW9LlHtc3fwJXSV+qWYG0r0vFtoKGCDhbnQH73Q NQmbGHMYRgYb/hiWbOnpXnrrh0XazOPDaCNJAT+dz283tSvrplorztRcrkCnNnYtlR1Wk2v O6Ci9VPd67qoIGCVPI2agxZNxDpq9GOVINnOspscPnPIZhp9iISG83aCI68IubVhlLuR7+N +fEehSlk2CuBNsH+zBqaQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V01:K0:WyjFJ/i977o=:MVOeMJlF8ruShqqlBJ1kod 6aiJPaUJmX6gnhgGYMD0yvpIOOb6cBqQlr1AJt3mlrbzf/e5kxDlW7d452vC7EBg51WzPKoZf wfRXZsEMN3HV4fe4R+drHjTjNaZoWj3dkbgpHi4hCExuxqpSTYqfFijwwsak0SUvAbI+kyCrr BL1wYBlOEWn2O/cnzMHIXrdxBYfu/DGH7NlDN0IcrR4+q3dXv5sID+T5ctuNy6SimJJaFfv5A pZLaUuyePHolEIvs/YRQle9A1wAlh2Sk1MAvyUFnucjWUd6m2VFu7YLgw13WQGamV7W64FnN+ jkfKLpUUIo//p48R+R9dDz07JQsrwJ950Y+GsOmA4f4AA4I7JSUCcMJ7eXbjTxaveM2McE5hy eHI6d15eKoVs4C7/k+MmQydK0AuL87dm4VJeAqkS9ZTTBrtTFJ9MSuXx5xO5M+y5KvQ1ishWG ZasZ9wZw+Namu0hwCRC9SnDqYErVzV1mlLTS9zG7y41fR1fP/B6KcYCN8Ol16fij15YXIEjD1 ClyDQz9JpnX5AESj6vb+DTGWk0cI/R1hpxbxHDINeVWvu4D/mbj17DLMC1+FS9hjz7WKSDrWe 8i72gF4aniq5p7qWeLO1lOFCOEcGAJIziT7KtpCGt3G1eWqItHDwFWQXxtS7U7XaEqtZJo85G lR5vqeiubErQcKveIm2ETqkhptOAWDsjZaHRi5Gzx2zsk3l1ACvpE9tKxiFyqysuSyeyRE4Up R7OJqxrx5ZxHXXeB X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 33281 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On 11/5/18 10:17 PM, Philip Rowlands wrote: > On Mon, 5 Nov 2018, at 20:30, Luiz Angelo Daros de Luca wrote: >> >> Once head read enough bytes to satisfy -c option, it stops reading input >> and quit. >> This is different from what -n does and it is also different from both >> FreeBSD and busybox head implementation. >> >> With GNU Coreutils head: >> >> $ echo -e "123\n456\n789" | { head -n 1; while read a; do echo "-$a-"; >> done; } >> 123 > > This is incomplete; head doesn't read everything, but more than one line. On my (rather aged Linux) system: > $ head --version > head (GNU coreutils) 8.25 > > $ seq 1864 | { head -n 1; while read a; do echo "-$a-"; done; } > 1 > -- > -1861- > -1862- > -1863- > -1864- > > What's special about 1860 lines of output? It's just over the amount of data which head reads from the pipe, 8192 bytes. Indeed, running 'head' via 'strace' seconds that: read(0, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14"..., 8192) = 8192 ... and: 'head' tries to "undo" the reading by calling lseek(), but that typically fails as stdin is a pipe: lseek(0, -8190, SEEK_CUR) = -1 ESPIPE (Illegal seek) Thus said, if your input was a regular file, then this positioning back to where the newline "\n" was would succeed: $ file=$(mktemp) \ && seq 4 > "$file" \ && { strace -ve read,lseek head -n 1; while read a; do echo "-$a-"; done; } < "$file" \ ; rm -f "$file" ... read(0, "1\n2\n3\n4\n", 8192) = 8 lseek(0, -6, SEEK_CUR) = 2 1 +++ exited with 0 +++ -2- -3- -4- Have a nice day, Berny From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 06 14:52:35 2018 Received: (at 33281) by debbugs.gnu.org; 6 Nov 2018 19:52:35 +0000 Received: from localhost ([127.0.0.1]:37826 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gK7Ot-0007MS-Bf for submit@debbugs.gnu.org; Tue, 06 Nov 2018 14:52:35 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:47550) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gK7Or-0007M9-6G for 33281@debbugs.gnu.org; Tue, 06 Nov 2018 14:52:33 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 16E6716017D; Tue, 6 Nov 2018 11:52:27 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id sirgC8zQ8Vg3; Tue, 6 Nov 2018 11:52:26 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 3875F16018A; Tue, 6 Nov 2018 11:52:26 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id SMDU99FIuM0K; Tue, 6 Nov 2018 11:52:26 -0800 (PST) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DC33116017D; Tue, 6 Nov 2018 11:52:25 -0800 (PST) Subject: Re: bug#33281: head does not consume input after '-c' is satisfied To: Philip Rowlands , 33281@debbugs.gnu.org References: <1541452669.415505.1566605800.6F507D78@webmail.messagingengine.com> From: Paul Eggert Openpgp: preference=signencrypt Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEuZWR1PsLBfgQTAQIAKAUCTIByZAIbAwUJEswDAAYLCQgHAwIG FQgCCQoLBBYCAwECHgECF4AACgkQ7ZfpDmKqfjRRGw/+Ij03dhYfYl/gXVRiuzV1gGrbHk+t nfrI/C7fAeoFzQ5tVgVinSh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MgBymCflK12eKfd2YYxnyg9cZazWA5VslvTxpm76hbg5oiAEH/Vg/8MxHyA nPhfrgwyPrmJEcVBafdspJnYQxBYNco2LFPIhlOvWh8r4at+s+M3Lb26oUTczlgdW1Sf3SDA 77BMRnF0FQyE+7AzV79MBN4ykiqaezQxtaF1Fy/tvkhffSo8u+dwG0EgJh+te38gTcISVr0G IPplLz6YhjrbHrPRF1CN5UuL9DBGjxuN35RLNVEfta6RUFlR6NctTjvrABEBAAHCwWUEGAEC AA8FAkyAcmQCGwwFCRLMAwAACgkQ7ZfpDmKqfjSrHA/+KzAKvTxRhA9MWNLxIyJ7S5uJ16gs T3oCjZrBKGEhKMOGX4O0GA6VOEryO7QRCCYah3oxSG38IAnNeiwJXgU9Bzkk85UGbPEd7HGF /VSeHCQwWou6jqUDTSDvn9YhNTdG0KXPM74aC+xr2Zow1O2mhXihgWKD0Dw+0LYPnUOsQ0KO FxHXXYHmRrS1OZPU59BLvc+TRhIhafSHKLwbXK+6ckkxBx6h8z5ccpG0Qs4bFhdFYnFrEieD LoGmnE2YLhdV6swJ9VNCS6pLiEohT3fm7aXm15tZOIyzMZhHRSAPblXxQ0ZSWjq8oRrcYNFx c4W1URpAkBCOYJoXvQfD5L3lqAl8TCqDUzYxhH/tJhbDdHrqHH767jaDaTB1+Talp/2AMKwc XNOdiklGxbmHVG6YGl6g8Lrbsu9NZEI4yLlHzuikthJWgz+3vZhVGyNlt+HNIoF6CjDL2omu 5cEq4RDHM44QqPk6l7O0pUvN1mT4B+S1b08RKpqm/ff015E37HNV/piIvJlxGAYz8PSfuGCB 1thMYqlmgdhd9/BabGFbGGYHA6U4/T5zqU+f6xHy1SsAQZ1MSKlLwekBIT+4/cLRGqCHjnV0 q5H/T6a7t5mPkbzSrOLSo4puj+IToNjYyYIDBWzhlA19avOa+rvUjmHtD3sFN7cXWtkGoi8b uNcby4U= Organization: UCLA Computer Science Department Message-ID: Date: Tue, 6 Nov 2018 11:52:25 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <1541452669.415505.1566605800.6F507D78@webmail.messagingengine.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 33281 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 11/5/18 1:17 PM, Philip Rowlands wrote: > To achieve consistency in the other direction, head could ignore the optimization to reduce the number of bytes read, and always read 8192 bytes, knowing that some would be discarded. Let's not do that. It's less efficient and less useful than what GNU 'head -c4' is doing now. > For widely differing values, the only way to produce the same residual output would be to consume all input data. Eeuuww. Let's *especially* not do that. From debbugs-submit-bounces@debbugs.gnu.org Sun Dec 23 00:44:00 2018 Received: (at 33281) by debbugs.gnu.org; 23 Dec 2018 05:44:00 +0000 Received: from localhost ([127.0.0.1]:60416 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gawYS-0003QZ-LN for submit@debbugs.gnu.org; Sun, 23 Dec 2018 00:44:00 -0500 Received: from mail-pf1-f169.google.com ([209.85.210.169]:39913) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gawYP-0003QC-VS; Sun, 23 Dec 2018 00:43:58 -0500 Received: by mail-pf1-f169.google.com with SMTP id r136so4494450pfc.6; Sat, 22 Dec 2018 21:43:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=BbwJltbJi6HuJHS3TVuCFoQTd5lBKZoW8/t77T05PPM=; b=H6nvWrUIh9Q2Tqj1A0opeSYaFgmw8bftDXuDNau3IfrgWgCTBZ/VR9IbVzWW34kvkD Mhf8/2/4+KCaLrcXNQIskCRhbIXNxA2caTO4HULMA0fFjwJ0f6powc6n6mxVnO2h2aZO AVuStTPkkmi8Y+ptPB68w+pTlbuk5Tmi9CoHlm1OlILxWqR4FLWGpF0ivDYUl+7D5iIm agqBgVIYD0tA1WXuTZPZQJ3KiaAtQ4MAimV4XLiCveHdEtfUZexmuaNb/teiSZgM/d+9 PXgLSHUTILuSgwx36JCyySQhNqeuPgpPoL5CLr7AcrYwkrCkN0MOvPLy0YtuCg0FHUhj nGCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BbwJltbJi6HuJHS3TVuCFoQTd5lBKZoW8/t77T05PPM=; b=eT8LKG/TYxccyfVk1t71L2JDczKZcgonggODE3TvSr+L78cLZ2AwC1o+R2oBPdGHdQ 4rqAxu0TAccYMP005DsMOVsVtD1ix7vXdhkZq6QFz78EOfaBBbgCZtIuwCBeY+EsRikJ DTOuliY+bexGBKXkhjcQeAhCT7jHIT8YlCK5hofBewnSAdAoHP5/8+6ojVwEE7aYRCfu 0RO9vECoo8vQmeXfkrBA0uJWLSUN8LU9SwNc37eYPT7TUySFZfjMf18OnAu5tJ+u16CJ KuOPzatNSIx8NkPeUDKkFqvdQ5seXgtAuqe8BdILJZm7te61sYT3BkZopWvKNJ0AxBLQ lu9A== X-Gm-Message-State: AJcUukd/otQgRgbvwB++ix+scBtJFqfdpDgvpjR9cHjXAKBsyYOHa71R 7Kdv8cTpWNDgX6GxxR3Y5MLY/6Fo X-Google-Smtp-Source: ALg8bN5QHpp9Vpfx7JlVLBhsScdSCgSXRkdUVIkgDssVVdYQC47FdIaO3Bj9PrZszUXXTnmxjz4Q3Q== X-Received: by 2002:a63:9b11:: with SMTP id r17mr8346075pgd.416.1545543831566; Sat, 22 Dec 2018 21:43:51 -0800 (PST) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id h69sm32252194pge.4.2018.12.22.21.43.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Dec 2018 21:43:50 -0800 (PST) Subject: Re: bug#33281: head does not consume input after '-c' is satisfied To: Paul Eggert , Philip Rowlands , 33281@debbugs.gnu.org References: <1541452669.415505.1566605800.6F507D78@webmail.messagingengine.com> From: Assaf Gordon Message-ID: Date: Sat, 22 Dec 2018 22:43:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 33281 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 33281 wontfix severity 33281 wishlist close 33281 stop Hello, On 2018-11-06 12:52 p.m., Paul Eggert wrote: > On 11/5/18 1:17 PM, Philip Rowlands wrote: >> To achieve consistency in the other direction, head could ignore the >> optimization to reduce the number of bytes read, and always read 8192 >> bytes, knowing that some would be discarded. > > Let's not do that. It's less efficient and less useful than what GNU > 'head -c4' is doing now. > >> For widely differing values, the only way to produce the same residual >> output would be to consume all input data. > > Eeuuww. Let's *especially* not do that. > Given the above, I'm closing this as "wontfix". Discussion can continue by replying to this thread. -assaf From unknown Wed Sep 10 10:35:53 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 20 Jan 2019 12:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator