當前位置:編程學習大全網 - 編程軟體 - linux bash如何table補齊預設參數

linux bash如何table補齊預設參數

1、自動補全是Bash Shell的功能,相關的命令(compgen、complete、compopt)

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"

  • 上一篇:請問fluent能夠使用cpu的雙線程技術嗎(例如6核12線程)
  • 下一篇:編程咨詢老師
  • copyright 2024編程學習大全網