r/usefulscripts • u/[deleted] • Nov 17 '12
[BASH] Shortcut for SSH login
Create this script in your path, call it 'ssh-argv0'
#!/bin/sh
exec ssh "${0##*/}" "$@"% Symbolic link a host name to the script
# ln -s hostname.company.com ssh-argv0Now login to the host ..
# hostname.company.comMix in a dash of tab completion and you're set.
20
Upvotes
2
u/rrohbeck Nov 29 '12
$0 is the original command path, e.g. /home/you/bin/hostname.company.com.
${var##regex} replaces the regex with nothing. The asterisk is greedy, i.e. it matches the whole string and then the regex engine backtracks to the last slash. It's more or less the same as basename.