Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Here goes:

function _command() {
    local cur
    if [ "$COMP_CWORD" -ge "2" ]; then
        COMPREPLY=($( compgen -W '$(pwd)' -- "$cur" ) )
        COMPREPLY=($( compgen -W "arg1 arg2" -- "$cur" ) )
complete -F _command command

This works well, so long as I source it.

What if I want it to auto-complete both outputs of pwd and some other arbitrary command, say hostname? What if I also wanted it to auto-complete on any file path?

share|improve this question

migrated from May 15 '11 at 6:58

This question came from our site for professional and enthusiast programmers. – Anders Lindahl May 13 '11 at 20:20

1 Answer 1

up vote 2 down vote accepted


COMPREPLY=($(compgen -W '$(pwd)' -- "$cur") $(compgen -W '$(hostname)' -- "$cur"))

(you want a bigger array, just make one) or

COMPREPLY=($( compgen -W '$(pwd; hostname)' -- "$cur" ) )

(still autocompleting one command).

share|improve this answer
For the first example, something like $( compgen -o default -- "$cur") does what I wanted... see my question edit. – Tshepang May 13 '11 at 23:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.