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"
}

最佳答案

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
}

关于bash - bash完成的'have'关键字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12874920/

10-13 01:48