Bash 脚本补全与环境变量定制指南
1. Bash 脚本补全
1.1 所需的 Bash 内部变量
编写 Bash 补全时,需要了解以下 Bash 内部变量:
| Bash 变量 | 描述 |
| ---- | ---- |
| COMP_WORDS | 命令行上输入的单词数组 |
| COMP_CWORD | 包含当前光标位置的单词索引 |
| COMPREPLY | 按下 [TAB][TAB] 后显示的补全结果数组 |
1.2 compgen 命令
compgen 是一个 shell 内置命令,它根据选项显示可能的补全内容,常用于 shell 函数中生成可能的补全。
1.3 Bash 补全示例
以下是一个为 bash_completion_example.sh 脚本编写的 Bash 补全文件示例:
# Filename: bash_completion_example
# Description: Bash completion for bash_completion_example.sh
_bash_completion_example()
{
# Declaring local variables
local cur prev opts
# An array variable storing the possible completions
COMPREP
超级会员免费看
订阅专栏 解锁全文
387

被折叠的 条评论
为什么被折叠?



