bash:获取以给定字符串开头的命令列表

是否可以使用Bash获取以某个字符串开头的命令列表?

我想在键入命令的开始后两次按来获取打印的内容,例如,将其存储在变量中。

回答:

您应该能够使用 compgen 命令,如下所示:

compgen -A builtin [YOUR STRING HERE]

例如,“ compgen -A Builtin l”返回

let 

local

logout

您可以使用其他关键字代替“ builtin”来获得其他类型的完成。Builtin为您提供Shell内置命令。“文件”为您提供本地文件名等。

下面是操作的列表(从BASH手册页 完整的 ,它使用 compgen ):

  alias      Alias names.  May also be specified as -a.

arrayvar Array variable names.

binding Readline key binding names.

builtin Names of shell builtin commands. May also be specified as -b.

command Command names. May also be specified as -c.

directory Directory names. May also be specified as -d.

disabled Names of disabled shell builtins.

enabled Names of enabled shell builtins.

export Names of exported shell variables. May also be specified as -e.

file File names. May also be specified as -f.

function Names of shell functions.

group Group names. May also be specified as -g.

helptopic Help topics as accepted by the help builtin.

hostname Hostnames, as taken from the file specified by the HOSTFILE shell

variable.

job Job names, if job control is active. May also be specified as

-j.

keyword Shell reserved words. May also be specified as -k.

running Names of running jobs, if job control is active.

service Service names. May also be specified as -s.

setopt Valid arguments for the -o option to the set builtin.

shopt Shell option names as accepted by the shopt builtin.

signal Signal names.

stopped Names of stopped jobs, if job control is active.

user User names. May also be specified as -u.

variable Names of all shell variables. May also be specified as -v.

以上是 bash:获取以给定字符串开头的命令列表 的全部内容, 来源链接: utcz.com/qa/413343.html

回到顶部