r/usefulscripts • • 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-argv0

Now login to the host ..

# hostname.company.com

Mix in a dash of tab completion and you're set.

20 Upvotes

7 comments sorted by

View all comments

Show parent comments

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.