[Toybox] [PATCH v2 1/1] teach head -c

Ilya Kuzmich ilya.kuzmich at gmail.com
Mon Jun 26 21:58:19 PDT 2017


On 26/06, Rob Landley wrote:
> On 06/01/2017 01:36 AM, Ilya Kuzmich wrote:
> > ping?
> 
> Let's see...
> 
> >> Not POSIX, but implemented in coreutils, busybox and freebsd.
> 
> 1) Do you have a use case for this? Or did you implement this because
> it's there? Denys added it to Busybox on February 25, 2013 but no
> message titles in the busybox mailing list around then mention "head" (I
> checked from February 2013 back to the previous November). I couldn't a
> bug report in https://bugs.busybox.net/buglist.cgi?quicksearch=head
> either. So it looks like when busybox was ~15 years old Denys added this
> because he could, not because anybody requested it or particularly
> noticed it was missing...
Convenience and compatibility.
It's widely used syntax, on github alone `"head -c" language:shell`
query returns 22,602 code results.
Personal perspective: my embedded linux $DAYJOB uses head -c alot.
> 
> 2) On ubuntu "echo hello | head -c 0" produces no output. This one looks
> like it falls back to line based behavior?
No, it does not.
I've just tested my implementation and it produces no output either.
> 
> 3) The ubuntu version has a more complicated -c behavior than you
> implemented, "head -c -6600 README" currently prints the first 24 bytes
> of that file. Why did you stop there? Why do we need this part but not
> all of it? (Our tail already implements the -c +k behavior, but somebody
> had an existing use case that needed it...)
It's just that I don't need negative values.
But hey - we could merge head.c and tail.c together.
> 
> 4) I am really uncomfortable pointing to posix _and_ a man page as a
> spec. (The old saying "A person with one watch always knows the time, a
> person with two is never sure."*) There are two other files that use man
> pages as their spec, and it's because neither posix nor lsb specify
> nsenter/unshare/partprobe. I'd rather just add it to a "deviations from
> posix" section if it's a posix command...
Reasonable.
> 
> *shrug* I admit this a more convenient syntax than doing it with dd
> (which is the first thing that comes to mind for me), but could you
> explain your reasoning for this patch a bit more? And/or any second
> opinions out there?
> 
> Thanks,
> 
> Rob
> 
> *  A person with three or more is going to have an endlessly expanding
> todo list, you can just tell. I say this having spent months wrestling
> with https://www.navcen.uscg.gov/pubs/gps/sigspec/gpssps1.pdf which
> requires _5_ nanosecond-accurate clocks to accurately tell you where you
> are. 4 in the satellites, one in the receiver.



More information about the Toybox mailing list