Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I'm looking for is not how to add autcompletion in bash for another program, but a way to get the result of what would have happened in bash to a string, basically:

autocomplete "/etc/apa"

would return


so I can use that in my script.

Any help is greatly appreciated, for all I can find is how to use the "complete" bash function, which does something different ;)

Cheers, rafael

share|improve this question
up vote 6 down vote accepted

Bash has a built-in command compgen which can help you a lot. For example, if you want to know which dirs would be auto-completed when you type cd /etc/s<TAB>:

$ compgen -d /etc/s

Then, the following command would tell you which dir you'll go into by cd /etc/se<TAB>:

$ compgen -d /etc/se

compgen can take most options of the complete command. See bash's manual for more details.

share|improve this answer
awesome, thanks! – xtin Mar 28 '13 at 7:24

You must log in to answer this question.

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