如何在 unix shell 中向我的自定义命令提供选项或参数作为建议

How to provide option or arguments as suggestions to my custom command in unix shell

我创建了一个自定义命令。在 shell 中使用它时,我需要它来获得建议。这些建议基本上是特定目录 X 中的子目录 Ys。(X 将在某些全局变量中可用)。

例如。 op [tab] 然后我应该得到目录 X 中所有目录的建议。

此外,如果我必须提供命令建议。我该怎么做?

这些功能称为 "autocomplete"(或类似的),internet on how to implement it in bash, for example this

上有许多资源可用

根据我从您的 post 那里得到的信息,假设您的子目录没有任何空格制表符或换行符,我认为您可以:

complete -W "$(find "X" -type d -maxdepth 1 -mindepth1)" op