On Sun, Mar 20, 2016 at 03:51:23PM -0400, Stephen Harris wrote:> On Sun, Mar 20, 2016 at 07:30:01PM +0000, Alex Bligh wrote: > > On 20 Mar 2016, at 19:15, Philip Hands <phil at hands.com> wrote: > > > Is anyone going to be upset by the resulting blank lines being added by > > > ssh-copy-id when the file was not missing a terminating newline? > > > > Well it would be at least mildly annoying my previously nice looking file > > now has a pile of blank lines in just because someone didn't know > > how to use their editor ... > > You can be pretty sure it'd end up causing a bug report as well > ("ssh-copy-id introduces blank lines into good files").How about something like: if [ "$(sed -n '${s/.*//;p}' ~/.ssh/authorized_keys | wc -l)" = 0 ]; then echo >> ~/.ssh/authorized_keys fi I feel like there must be a neater but still portable way to do this, and the above would require some careful quoting to work in the context of ssh-copy-id. -- Colin Watson [cjwatson at debian.org]
On Sun, Mar 20, 2016 at 08:30:33PM +0000, Colin Watson wrote:>How about something like: > > if [ "$(sed -n '${s/.*//;p}' ~/.ssh/authorized_keys | wc -l)" = 0 ]; then > echo >> ~/.ssh/authorized_keys > fi > >I feel like there must be a neater but still portable way to do this,Maybe if [ ! -z `tail -c 1 ~/.ssh/authorized_keys` ] ; then Mike Stone
Michael Stone <mstone at mathom.us> writes:> On Sun, Mar 20, 2016 at 08:30:33PM +0000, Colin Watson wrote: >>How about something like: >> >> if [ "$(sed -n '${s/.*//;p}' ~/.ssh/authorized_keys | wc -l)" = 0 ]; then >> echo >> ~/.ssh/authorized_keys >> fi >> >>I feel like there must be a neater but still portable way to do this, > > Maybe > > if [ ! -z `tail -c 1 ~/.ssh/authorized_keys` ] ; thenAh, thanks for that, I'd forgotten about the -c option. I think that adding the following, just before the 'mkdir .ssh', should do the trick: [ "`tail -c1 .ssh/authorized_keys 2>/dev/null`" ] && echo > .ssh/authorized_keys ; anyone know of portability issues with that? 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/b9239fa8/attachment.bin>