庆典:得到命令列表开始给定的字符串 [英] bash: get list of commands starting with a given string

查看:241
本文介绍了庆典:得到命令列表开始给定的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能得到,使用bash,从某些字符串命令的列表?

我想会得到什么打印击球<标签>输入命令的开始,并且例如两次后,将其存储在变量中。

Is it possible to get, using Bash, a list of commands starting with a certain string?
I would like to get what is printed hitting <tab> twice after typing the start of the command and, for example, store it inside a variable.

推荐答案

您应该能够使用的 compgen 的命令,就像这样:

You should be able to use the compgen command, like so:

compgen -A builtin [YOUR STRING HERE]

例如,compgen -A内置L返回

For example, "compgen -A builtin l" returns

let 
local 
logout

您可以使用其他的关键字,内置,以获得其他类型的完成。内建给你shell内建命令。 文件给你的本地文件名等。

You can use other keywords in place of "builtin" to get other types of completion. Builtin gives you shell builtin commands. "File" gives you local filenames, etc.

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

Here's a list of actions (from the BASH man page for complete which uses 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.

这篇关于庆典:得到命令列表开始给定的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆