"Tom G. Christensen" <tgc at jupiterrise.com> writes:> On 22/03/16 08:34, Philip Hands wrote: >> >> [ "`tail -c1 .ssh/authorized_keys 2>/dev/null`" ] && echo > .ssh/authorized_keys ; >> >> anyone know of portability issues with that? >> > > On Solaris 10 and older /usr/bin/tail does not understand the -c1 > syntax, it needs -1c instead.OK, it seems that tail from coreutils on Debian can deal with -1c as well -- odd -- is this actually the portable option despite not being in the manual? BTW can Solaris 10's tail handle it with a space after the c, thus: tail -c 1 Cheers, Phil. -- |)| Philip Hands [+44 (0)20 8530 9560] HANDS.COM Ltd. |-| http://www.hands.com/ http://ftp.uk.debian.org/ |(| Hugo-Klemm-Strasse 34, 21075 Hamburg, GERMANY -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 818 bytes Desc: not available URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20160322/cc6afc3f/attachment.bin>
On 22/03/16 22:32, Philip Hands wrote:> "Tom G. Christensen" <tgc at jupiterrise.com> writes: > >> On 22/03/16 08:34, Philip Hands wrote: >>> >>> [ "`tail -c1 .ssh/authorized_keys 2>/dev/null`" ] && echo > .ssh/authorized_keys ; >>> >>> anyone know of portability issues with that? >>> >> >> On Solaris 10 and older /usr/bin/tail does not understand the -c1 >> syntax, it needs -1c instead. > > OK, it seems that tail from coreutils on Debian can deal with -1c as > well -- odd -- is this actually the portable option despite not being in > the manual? > > BTW can Solaris 10's tail handle it with a space after the c, thus: > > tail -c 1 >No. It seems the default tail in /usr/bin is the old one from the BSD days of SunOS 4 hence it does not know the more modern syntax. You can see the manpage here: https://docs.oracle.com/cd/E26502_01/html/E29030/tail-1.html -tgc
On Tue, Mar 22, 2016 at 10:32:43PM +0100, Philip Hands wrote:>OK, it seems that tail from coreutils on Debian can deal with -1c as >well -- odd -- is this actually the portable option despite not being in >the manual? > >BTW can Solaris 10's tail handle it with a space after the c, thus: > > tail -c 1That's the POSIX syntax. Friends don't let friends use the non-POSIX solaris utilities. Mike Stone
Michael Stone <mstone at mathom.us> writes:> On Tue, Mar 22, 2016 at 10:32:43PM +0100, Philip Hands wrote: >>OK, it seems that tail from coreutils on Debian can deal with -1c as >>well -- odd -- is this actually the portable option despite not being in >>the manual? >> >>BTW can Solaris 10's tail handle it with a space after the c, thus: >> >> tail -c 1 > > That's the POSIX syntax. > > Friends don't let friends use the non-POSIX solaris utilities.I guess that's a function of the PATH in use, and we don't have much control over that unless I were to start adding weird tests in this command line, so I'm not quite sure what you're trying to say there. Anyway, having read the GNU coreutils info page, I see it supports the -1c "obsolete" usage, and recent BSD manpages say they support the same "historical" usage too, so the best bet would seem to be -1c (unless there are some modern tail implementations that fail to support this). On the strength of that, and having considered suggestions in this thread, I'm settling on adding this after the ``mkdir .ssh &&'' : f=.ssh/authorized_keys && { [ -z "`tail -1c $f 2>/dev/null`" ] || echo >> $f ; } && I've inverted the test, in order that the series of &&'s can continue, it's using -1c for tail, as that seems likely to be maximally portable, likewise `` is more portable than $(), I don't see much benefit in creating the file just so that the tail won't fail, so I've got the 2>/dev/null instead (I'm open to persuasion on that, since if one creates the file, and doesn't discard the STDERR, then if tail manages to fail for some other reason, we'd perhaps find out about it), and the use of a variable ($f) removes duplication later in the line, and keeps the line length under 255 which could conceivably be a limit in some awful shell somewhere. Did I miss anything? Cheers, Phil. -- |)| Philip Hands [+44 (0)20 8530 9560] HANDS.COM Ltd. |-| http://www.hands.com/ http://ftp.uk.debian.org/ |(| Hugo-Klemm-Strasse 34, 21075 Hamburg, GERMANY -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 818 bytes Desc: not available URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20160323/c8d09aaf/attachment.bin>