shell command line auto completion :内置变量请参考 unix坏境高级编程
# Enable auto-completionfunction _hosts() { COMPREPLY=() local cur=${COMP_WORDS[COMP_CWORD]}; local com=${COMP_WORDS[COMP_CWORD-1]}; case $com in 'ssh') local hosts=($(cat /etc/AutoTab/hosts)) COMPREPLY=($(compgen -W '${hosts[@]}' -- $cur)) ;; esac}complete -F _hosts ssh
原文地址:Shell Auto Completion, 感谢原作者分享。 有时不但是必要的,而且是很有必要的。