[PATCH] Use POSIX standardized options for head(1) and tail(1)

Mark D. Baushke mdb at juniper.net
Fri May 1 15:14:21 AEST 2020


Hi Damien,

Damien Miller <djm at mindrot.org> writes:

> Thanks, but I don't think we're going to merge this one because I'm
> somewhat worried that some systems we currently build on do not support
> the -n syntax. Conversely, AFAIK everything* supports -number.

Michael Forney said that he was trying to run on a system that did NOT
support head -number and tail +number old-style format.

This is why I suggested use of 'sed' instead of 'head' and 'tail'. The
sed command predates both head and tail and the following idiom in sed
should be common going back to at least 1984 when I used sed in this way
on the following systems:

   Berkeley Software Distribution (4.4 BSD-Lite).
   Mt Xinu 4.3
   AIX 3 (1989) - AIX 4 (1994)
   HP/UX System V (1989)
   SunOS 3.0Beta1 (1986) thru Soliars 11
   FreeBSD 2.2.6 thru FreeBSD/11
   OpenBSD 2.7
   Cray X/MP

I recommend the change from

     (head -2 .depend; tail +3 .depend | sort) >.depend.tmp

to

     (sed 2q .depend; sed 1,2d .depend | sort) > .depend.tmp

should do the job correctly for all instances of sed I have ever used.

Failing this solution, coming up with a 'configure' script test might be
possible that provides for a compatibility test for using of -n options
for head and tail

	Be safe, stay healthy,
	-- Mark


More information about the openssh-unix-dev mailing list