[PATCH] Use POSIX standardized options for head(1) and tail(1)
Mark D. Baushke
mdb at juniper.net
Sun Apr 26 13:10:58 AEST 2020
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.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.
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
More information about the openssh-unix-dev
mailing list