Why is the /usr/bin/line program not included in the gentoo util-linux package? Debian stable does include it. It can be quite useful in shell scripts that need to read input line by line (as opposed to char by char, which is what the read built in does).
Upstream doesn't build it by default. https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=c135a8bdc3b2d21fba2c0e6e09dc785498736061
From Documentation/deprecated.txt: What: line(1) command Why: useless, nobody uses this command, head(1) is better https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/tree/Documentation/deprecated.txt#n52
I don't know where the commit comment that "head is better" comes from. Maybe the author of that comment didn't think of reading from a pipe? Compare: 1!~ jot 100 1 | for n in 0 1 2 3 4 5 6 7 8 9 ; do read -r ; echo $REPLY ; done 2!~ jot 100 1 | for n in 0 1 2 3 4 5 6 7 8 9 ; do line ; done 3!~ jot 100 1 | for n in 0 1 2 3 4 5 6 7 8 9 ; do head -n1 ; done Why the difference? stdio buffering, which can only be defeated by going through *major* ugly hoops. As for 'nobody uses it', that is because everybody uses the horribly wasteful 1! above. I hope conventional wisdom (which in this case is wrong) doesn't drive what gets included in gentoo :-)
From what I can tell, bash's read builtin and the "line" command from util-linux both read from stdin one character at a time, and produce identical output given your examples. head(1) reads 8192 characters at a time, so only the number "1" is printed from your example.
Anyway, I can't see any harm in making this optional via a USE flag, or even just enabling it unconditionally.
(In reply to Ian Zimmerman from comment #0) > It can be quite useful in shell > scripts that need to read input line by line (as opposed to char by char, > which is what the read built in does). To clarify/correct this: there's really no such thing as "reading input line by line". On Linux, you read a specified number of bytes, depending on the buffer size you pass to the read(2) syscall. The line(1) command simply reads one character at a time, until it encounters a newline character. This is the same thing the read(1) builtin command does; there's no real efficiency gain by using one or the other. You might pick up a small speed boost with line(1) since you don't need to "echo" the results to stdout from the shell.
Mike: yes, you're right about the efficiency. I didn't think about that clearly enough. Correctness wise, that is what I was trying to show: head is no replacement. Anyway, I have found a workaround for my present case, so I'm fine with whatever way you dispose with this critter. Until next time :-)
commit a18b0f04ff1de57f0e61e8d92995497dcf99caca Author: Lars Wendler <polynomial-c@gentoo.org> Date: Thu May 25 23:17:55 2017 sys-apps/util-linux: Bump to version 2.30_rc2 Package-Manager: Portage-2.3.6, Repoman-2.3.2 Teis version installs the "line" tool but it's not keyworded. The forthcoming 2.30 release will have keywords.