bashdebian

bash: complete: -I: invalid option


I'm using the bash complete -I option as follows:

__cmp_exec() {
    local curr="$2"
    case "$curr" in
        ./*)
            local selected=$(find "." ! -type d -executable | fzf --query "$curr")
        if [[ -n "$selected" ]]; then
            COMPREPLY=( "$selected" )
        else
            COMPREPLY=()
        fi
    esac
}


complete -I -F __cmp_exec -o bashdefault>

Locally everything works. But when I use the script on our server I get an error:

bash: complete: -I: invalid option

This is the bash version I'm running:

$ bash --version
bash --version
GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
history -a

I thought bash supports the -I flag from version 4.0, am I wrong in assuming so?


Solution

  • I thought it was after v4.4 but in the release notifications of Bash-5.0 it says:

    dd. The `complete' builtin now accepts a -I option that applies the completion to the initial word on the line.

    So if you upgrade your version of bash, you can use the specified option feature with your script.

    Edit: There is also Bash 5.2 manual that indicates -I option as a feature.