Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

/etc/apache2/

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

1 Answer 1

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
/etc/security
/etc/sgml
/etc/skel
/etc/ssh
/etc/ssl
/etc/subversion
/etc/sudoers.d
/etc/sysctl.d
$

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

$ compgen -d /etc/se
/etc/security
$

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

Your Answer

 
discard

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.