I have a script for extending bash-completion for certain commands. If I type command1 and do a tab, it should auto-complete with a file directory (and the files). It works fine expect for one inconvenient issue. It adds an extra white space every time it auto-complete. So if you are trying to reach sub-directories from root, for example, every sub-directory you get to an extra space gets added and it kinda defeats the purpose of extending bash-completion. I am new to bash. Is this a result of how I wrote the script or is this just how tab-completion behaves when you extend it?

local cur prev opts
opts="command1 command2"
serviceOpts="opt1 opt2"

case "${prev}" in
        COMPREPLY=( $(compgen -f ${cur}) )
        return 0
        COMPREPLY=( $(compgen -W "${serviceOpts}" ${cur}) )
        return 0
  • 1
    You may want to use shell check before posting.
    – Jedi
    Commented Jul 6, 2016 at 10:08

1 Answer 1


There is an option -o nospace to the complete command that tells Readline to not add that extra space. Docs

You must log in to answer this question.

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