conn() { local host case "$1” in ‘a’) host=1.2.3.4 ;; ‘b’) host=5.6.7.8 ;; ‘*’) echo 'conn what?' ;; esac
shift 1 ssh $host “$@" }
kodango
2014-08-08 00:00:51 +08:00
将以下内容添加到~/.bash_profile文件中:
# Auto complete ssh server defined in ~/.ssh/config #complete -W "$(awk '/^Host/{if ($2!="*") print $2}' ~/.ssh/config)" ssh
# Define ssh alias for server defined in ~/.ssh/config for host in $(awk '/^Host/{if ($2!="*") print $2}' ~/.ssh/config); do alias $host="ssh $host" done 然后 source ~/.bash_profile或者重新登录 shell,直接键入服务器别名,例如test,来ssh到相应的机器。