2、complete實例
創建hello_complete,內容:
complete -F _hello_complete_func hello.sh
_hello_complete_func ()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="help usage version"
if [[ ${cur} == * ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
3、source hello_complete讓補全的參數生效。
4、創建hello.sh
#!/bin/sh
echo "hello world"
5、./hello.sh [TAB][TAB]
help usage version
6、不用complete簡單的提醒需要輸入參數
#!/bin/sh
str=$1
if [[ $1 == '' ]];then
echo "Usage: $0 help|version"
exit 0;
fi
echo "$str"