bash完成的'have'关键字

时间:2012-10-13 16:59:25

标签: bash autocomplete

bash中的have是关键字吗?或者bash完成脚本使用的语言不是bash?

have gcc &&
_gcc()
{

很常见。请参阅:grep "have .* &&" /etc/bash_completion.d/*

我找不到有关我看过的bash完成教程的任何信息,但在man bash中找不到任何信息。它也很难谷歌"有"。我在哪里可以找到关于此的文档?

我猜测它与确保gcc中存在PATH有关吗?​​

编辑:是的。 /etc/bash_completion包含:

have()
{
    unset -v have
    # Completions for system administrator commands are installed as well in
    # case completion is attempted via `sudo command ...'.
    PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
    have="yes"
}

1 个答案:

答案 0 :(得分:19)

have_have只是基本bash_completion文件中定义的两个函数。在两者之间,它们形成了内置type命令的包装器,以确定特定的命令/程序是否可用。

# This function checks whether we have a given program on the system.
#
_have()
{
    # Completions for system administrator commands are installed as well in
    # case completion is attempted via `sudo command ...'.
    PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type $1 &>/dev/null
}

# Backwards compatibility for compat completions that use have().
# @deprecated should no longer be used; generally not needed with dynamically
#             loaded completions, and _have is suitable for runtime use.
have()
{
    unset -v have
    _have $1 && have=yes
}