gpt4 book ai didi

linux - 如何在 SLES 12 中自动完成命令的选项?

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:56 24 4
gpt4 key购买 nike

我有一项服务,比如 xyz。截至目前,我可以分别使用命令 rcxyz start、rcxyz stop 和 rcxyz restart 来启动、停止或重新启动该服务。它工作正常。

我想做的就是,如果我输入 rcxyz 并按 <TAB> ,我希望自动完成三个选项(开始、停止和重新启动)。

我引用了 stackoverflow 中的其他 bash_completion 相关问题并尝试编写一个虚拟脚本 /etc/bash_completion.d/rcxyz.sh我在里面写了

complete -c rcxyz

当我输入 rcxyz 并按 <TAB> 时,我期待着,我将获取可用命令列表作为参数。但它没有用。

我错过了什么吗?

最佳答案

你应该写:

complete -W 'start stop restart' rcxyz

参见 bash 的手册:

-W wordlist

The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is expanded. The possible completions are the members of the resultant list which match the word being completed.

关于linux - 如何在 SLES 12 中自动完成命令的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43061672/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com