'have' keyword for bash completion

后端 未结 1 2054
感动是毒
感动是毒 2021-02-12 15:30

Is have a keyword in bash? Or do bash completion scripts use a language that is not bash?

have gcc &&
_gcc()
{

It is commo

1条回答
  •  [愿得一人]
    2021-02-12 16:05

    have and _have are just two functions defined in the base bash_completion file. Between the two, they form a wrapper around the built-in type command to determine if a particular command/program available.

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

    0 讨论(0)
提交回复
热议问题