Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 619610 - sys-apps/util-linux: where is the tool "line"?
Summary: sys-apps/util-linux: where is the tool "line"?
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-24 21:39 UTC by Ian Zimmerman
Modified: 2017-05-25 21:27 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Zimmerman 2017-05-24 21:39:45 UTC
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).
Comment 2 Mike Gilbert gentoo-dev 2017-05-24 22:36:34 UTC
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
Comment 3 Ian Zimmerman 2017-05-24 23:28:38 UTC
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 :-)
Comment 4 Mike Gilbert gentoo-dev 2017-05-25 04:17:56 UTC
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.
Comment 5 Mike Gilbert gentoo-dev 2017-05-25 04:36:42 UTC
Anyway, I can't see any harm in making this optional via a USE flag, or even just enabling it unconditionally.
Comment 6 Mike Gilbert gentoo-dev 2017-05-25 04:48:53 UTC
(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.
Comment 7 Ian Zimmerman 2017-05-25 15:21:30 UTC
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 :-)
Comment 8 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2017-05-25 21:27:44 UTC
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.