Huh. ssh used to offer this feature natively -- just symlink any hostname to the ssh binary -- but it turns out that they removed this about ten years ago.
(I feel old...)
A feature which was copied from rlogin and rsh, I seem to remember.
Me too.
${0##*/} ... are you looking for the basename(1) command? Posix requires support for this usage, but it does not work with many traditional shells, e.g., Solaris 10 /bin/sh.
Here's how to work around it:
#!/bin/sh
exec ssh "$(basename "$0")" "$@"
FWIW it's a little easier to read, too.Sun was so into keeping backward compatibility intact they would not update the default /bin/sh because of some compatibility issues that could affect customers. So they included the newer XPG4 sh in a different location (it is a POSIX-compliant ksh88): /usr/xpg4/bin/sh. So you can write:
#!/usr/bin/env sh
So that users who have setup PATH=/usr/xpg4/bin:$PATH get the correct shell and everything works fine.
Re:SSH Tricks
by JoshTriplett on Monday September 19, 2011 @10:01PM
(#3015963)
No, I'm not looking to fork and exec a second program, and short of busybox most shells don't have basename built in.
Common idiom, works in POSIX /bin/sh, bash, dash, ash, and every other sh I've encountered. I make a point of avoiding bashisms in /bin/sh scripts, but I have no problem counting on POSIX sh. :)
If you're used to using "ssh user@box foo", and not always for the same user (in which case you could use "User" in .ssh/config), you can do the same thing via "box -l user foo"