I'm attempting to do bash completion for a command, and everything is working as normal with the full word commands, but when I try to complete the "--" flags, with the following code (following by a complete -F _keybase keybase) using any letter after the two tacks (i.e. keybase --h<TAB>) I get a compgen usage error. (keybase --<TAB> works as expected however). This is on Ubuntu 18.04. I'm sourcing this file in the current shell session and not as part of a logon script (yet).

_keybase() {
    local cur prev opts

    #...code removed for brevity

    if [[ ${cur} == -* ]]; then
# complete the "--" parameters
        opts=$(keybase help advanced | grep -Po '\-\-[a-z\-]+' | tr "\n" " ")
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )

This is what prints out when I type keybase --h<TAB>

keybase --hbash: compgen: --: invalid option
compgen: usage: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]

I tweaked the escaping of the quotes, and added/removed the newlines in the defintion of $opt and added/removed the "--" as the second argument to compgen (I added these at the behest of a Debian article explaing bash completion keybase help advanced | grep -Po '\-\-[a-z\-]+' | tr "\n" " " outputs:

--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version 

and when I echo the command that compgen is expected to run with echo "compgen -W \"${opts}\" -- ${cur}" I get the command I expect and indeed one that runs just fine at the terminal:

compgen -W "--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version " -- --h
  • Curiously, this same code works fine on Fedora. Perhaps this is an Ubuntu bug. Mar 4, 2019 at 3:04

1 Answer 1


Turns out the code works find on Fedora 29, leading me to believe this is a bug in Ubuntu and not in the script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .