From: Jeff King Date: Fri, 01 Jul 2016 18:01:43 GMT Subject: Re: [PATCH v4 1/5] t9300: factor out portable "head -c" replacement Message-ID: <20160701180142.GC16235@sigill.intra.peff.net> In-Reply-To: On Fri, Jul 01, 2016 at 10:23:05AM -0700, Junio C Hamano wrote: > Jeff King writes: > > > In shell scripts it is sometimes useful to be able to read > > exactly N bytes from a pipe. Doing this portably turns out > > to be surprisingly difficult. > > I'd rotate the above by three words ;-). > > It is sometimes useful to be able to read > exactly N bytes from a pipe. Doing this portably turns out > to be surprisingly difficult > in shell scripts. Yeah, I'd very much agree with that (feel free to mark it up as you apply). > > - "dd bs=1 count=$n" fixes the partial read problem (all > > reads are 1-byte, so there can be no partial response). > > It does make a lot of write() calls, but for our tests > > that's unlikely to matter. > > It makes me wonder if it helps to use different ibs and obs if many > writes bother you, but because this patch moves us away from dd, > that is a moot point. Actually, I just mis-spoke (mis-wrote?). I meant to say that it makes a lot of read() calls. (It probably also makes a lot of write() calls, but that is beside the point). -Peff