了解“compgen”内置命令

了解“compgen”内置命令

help compgen

$ help compgen
compgen: compgen [-abcdefgjksuv] [-o option]  [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]
    Display possible completions depending on the options.
    
    Intended to be used from within a shell function generating possible
    completions.  If the optional WORD argument is supplied, matches against
    WORD are generated.
    
    Exit Status:
    Returns success unless an invalid option is supplied or an error occurs.

选项[-abcdefgjksuv]代表什么?

换句话说,我想知道如何使用所有选项。

答案1

命令选项compgen与 相同complete,但-p和除外-r。从compgen手册页:

compgen
 compgen [option] [word]
 Generate possible completion matches for word according to the options, which 
 may be any option accepted by the complete builtin with the exception of -p 
 and -r, and write the matches to the standard output

对于选项[abcdefgjksuv]

  • -a表示别名的名称
  • -b表示 shell 内建函数的名称
  • -c表示所有命令的名称
  • -d表示目录名称
  • -e表示导出的 shell 变量的名称
  • -f表示文件名
  • -g表示组的名称
  • -j表示职位名称
  • -k表示 shell 保留字的名称
  • -s表示服务名称
  • -u表示用户名的名称
  • -v表示 shell 变量的名称

你可以看到完整的手册页这里

答案2

在奥莱利有一本书(Arnold Robbins 的 bash 快速参考compgen),还具有完整描述的提示表单选项。获取完整的文档除了上面列出的之外还有一些其他选项。它们可能与当前版本无关,但当前版本文档中不再或未描述某些选项。

截至目前,我在网上看到这些大写选项用于调用compgen或在完整文档中提到!

compgen [option] [word]
complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G globpat] [-W wordlist]
      [-P prefix] [-S suffix] [-X filterpat] [-F function]
      [-C command] name [name ...]
      complete -pr [name ...]
  • -A 操作 = 该操作可以是以下操作之一,用于生成可能完成的列表:(请参阅链接)
  • -C command = 在子 shell 中运行命令并使用其输出作为完成列表。
  • -F function = 在当前 shell 中运行 shell 函数。返回后,从 COMPREPLY 数组中检索完成列表。
  • -G globpat = 文件名扩展模式 globpat 被扩展以生成可能的补全。
  • -P prefix = 在应用所有其他选项后,在每个可能的完成的开始处添加前缀。
  • -S suffix = 在应用所有其他选项后,将后缀附加到每个可能的完成中。
  • -W wordlist = 使用 IFS 特殊变量中的字符作为分隔符来分割单词列表,并扩展每个结果单词。可能的完成是结果列表中与正在完成的单词匹配的成员。
  • -X filterpat = filterpat 是用于文件名扩展的模式。它应用于由前面的选项和参数生成的可能完成列表,并且每个与filterpat匹配的完成都将从列表中删除。前导 '!'在filterpat中否定模式;在这种情况下,任何不匹配 filterpat 的补全都会被删除。

可以在以下位置找到该文档的相当详尽的版本:可编程完成内置函数

由于这两个命令都是内置命令,因此官方文档位于您本地手册页对于bash。使用搜索选项在其中查找相关部件。抱歉,但在任一视图变体中,甚至在互联网服务上,布局看起来都有些破损(生成的布局中的可用性降低)。

相关内容