Michael Forney
2020-Apr-26 01:43 UTC
[PATCH] Use POSIX standardized options for head(1) and tail(1)
--- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 304d96cd..47e04c02 100644 --- a/Makefile.in +++ b/Makefile.in @@ -353,7 +353,7 @@ depend-rebuild: rm -f config.h touch config.h makedepend -w1000 -Y. -f .depend *.c 2>/dev/null - (head -2 .depend; tail +3 .depend | sort) >.depend.tmp + (head -n 2 .depend; tail -n +3 .depend | sort) >.depend.tmp mv .depend.tmp .depend rm -f config.h -- 2.26.2
Mark D. Baushke
2020-Apr-26 03:10 UTC
[PATCH] Use POSIX standardized options for head(1) and tail(1)
Hi Michael, Using POSIX command-line semantics is a fine goal. Someone might drop the backward-compatiblity of the commands and then things would begin to break. However, there is an alternative. Do not use these POSIX commands that have changed their command-line syntax if one that exists and is more stable is also available.> @@ -353,7 +353,7 @@ depend-rebuild: > rm -f config.h > touch config.h > makedepend -w1000 -Y. -f .depend *.c 2>/dev/null > - (head -2 .depend; tail +3 .depend | sort) >.depend.tmp > + (head -n 2 .depend; tail -n +3 .depend | sort) >.depend.tmp > mv .depend.tmp .depend > rm -f config.hI am speaking of the use of 'sed' which has been pretty stable since at least 1992 and mostly the same going back to 1974. Using sed for compatibility with all possible portable releases seems 'better' to me than just upgrading a command because POSIX thinks it is a good idea. For example: head -2 == head -n 2 == sed 'n;q' tail +3 == tail -n +3 == sed '1,2d' The sed program has been around a lot longer without these command-line semantics changing for POSIX. These idioms should work fine going back to at least the BSD version of sed from 1992 by Diomidis Spinellis and maybe even going back to Lee E. McMahon's version in 1974. @@ -353,7 +353,7 @@ depend-rebuild: rm -f config.h touch config.h makedepend -w1000 -Y. -f .depend *.c 2>/dev/null - (head -2 .depend; tail +3 .depend | sort) >.depend.tmp + (sed 'n;q' .depend; sed '1,2d' .depend | sort) >.depend.tmp mv .depend.tmp .depend rm -f config.h The idea of the OpenSSH portable release is to be portable across a LOT of UNIX (and even some non-UNIX releases). If that is the goal, why enforce the need to fetch and build POSIX-compliant versions of head and tail for very old systems? Be safe, stay healthy, -- Mark
Michael Forney
2020-Apr-26 07:46 UTC
[PATCH] Use POSIX standardized options for head(1) and tail(1)
On 2020-04-25, Mark D. Baushke <mdb at juniper.net> wrote:> Hi Michael,Hi Mark,> Using POSIX command-line semantics is a fine goal. Someone might drop > the backward-compatiblity of the commands and then things would begin to > break.Indeed, that's what motivated the patch. The version of tail on my system does not support the legacy options.> However, there is an alternative. Do not use these POSIX commands > that have changed their command-line syntax if one that exists and is > more stable is also available. > >> @@ -353,7 +353,7 @@ depend-rebuild: >> rm -f config.h >> touch config.h >> makedepend -w1000 -Y. -f .depend *.c 2>/dev/null >> - (head -2 .depend; tail +3 .depend | sort) >.depend.tmp >> + (head -n 2 .depend; tail -n +3 .depend | sort) >.depend.tmp >> mv .depend.tmp .depend >> rm -f config.h > > I am speaking of the use of 'sed' which has been pretty stable since at > least 1992 and mostly the same going back to 1974. > > Using sed for compatibility with all possible portable releases seems > 'better' to me than just upgrading a command because POSIX thinks it is > a good idea.This seems like a fine option to me.> For example: > > head -2 == head -n 2 == sed 'n;q'Another possibility is `sed 2q`, which works for any number. It's even mentioned in the rationale section as a way to simulate head(1).> tail +3 == tail -n +3 == sed '1,2d' > > The sed program has been around a lot longer without these command-line > semantics changing for POSIX. > > These idioms should work fine going back to at least the BSD version of > sed from 1992 by Diomidis Spinellis and maybe even going back to Lee E. > McMahon's version in 1974. > > @@ -353,7 +353,7 @@ depend-rebuild: > rm -f config.h > touch config.h > makedepend -w1000 -Y. -f .depend *.c 2>/dev/null > - (head -2 .depend; tail +3 .depend | sort) >.depend.tmp > + (sed 'n;q' .depend; sed '1,2d' .depend | sort) >.depend.tmp > mv .depend.tmp .depend > rm -f config.h > > The idea of the OpenSSH portable release is to be portable across a LOT > of UNIX (and even some non-UNIX releases). If that is the goal, why > enforce the need to fetch and build POSIX-compliant versions of head and > tail for very old systems?I think this script is only necessary to rebuild the .depend file, which is not usually necessary, but you make a good point. I didn't realize that some implementations did not support the -n option. The change you suggested sounds good to me. -Michael
David Newall
2020-Apr-26 11:58 UTC
[PATCH] Use POSIX standardized options for head(1) and tail(1)
Hi Michael, Does everything that we care about (which is a lot) do POSIX arguments to head and tail?? What systems that do do POSIX don't accept the traditional arguments (no "-n".)? Cheers, David
David Newall
2020-Apr-26 12:05 UTC
[PATCH] Use POSIX standardized options for head(1) and tail(1)
On 26/4/20 9:28 pm, David Newall wrote:> Hi Michael, > > Does everything that we care about (which is a lot) do POSIX arguments > to head and tail?? What systems that do do POSIX don't accept the > traditional arguments (no "-n".)? > > Cheers, > > DavidQuestion withdraw; already answered.
Damien Miller
2020-May-01 04:33 UTC
[PATCH] Use POSIX standardized options for head(1) and tail(1)
Hi, 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. -d * except some GNU tools if you don't set a magic env var, which we do On Sat, 25 Apr 2020, Michael Forney wrote:> --- > Makefile.in | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/Makefile.in b/Makefile.in > index 304d96cd..47e04c02 100644 > --- a/Makefile.in > +++ b/Makefile.in > @@ -353,7 +353,7 @@ depend-rebuild: > rm -f config.h > touch config.h > makedepend -w1000 -Y. -f .depend *.c 2>/dev/null > - (head -2 .depend; tail +3 .depend | sort) >.depend.tmp > + (head -n 2 .depend; tail -n +3 .depend | sort) >.depend.tmp > mv .depend.tmp .depend > rm -f config.h > > -- > 2.26.2 > > _______________________________________________ > openssh-unix-dev mailing list > openssh-unix-dev at mindrot.org > https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev >
Mark D. Baushke
2020-May-01 05:14 UTC
[PATCH] Use POSIX standardized options for head(1) and tail(1)
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