1

I would like to get the same possible autocomplete list as hitting [Tab][Tab] in bash but with a command. Is there anyway to do that?

marked as duplicate by muru, Scott, Jeff Schaller, vonbrand, Karlson Jan 29 '16 at 4:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • In theory you could echo -e "\011\011" | bash (011 is tab char), but in practice I don't think that will work, ever. – cat Jan 29 '16 at 0:15
4

You can use compgen, which is typically the program that's invoked when you hit tab twice.

$ compgen -c c
cls
case
coproc
command_not_found_handle
caller
cd
command
compgen
complete
compopt
continue
clamd
cracklib-check
cpgr
cupsreject
cupsdisable
cupsaccept
cron
cppw
<100's more lines...>

It includes shell builtins, too! See this question and man compgen.

Note the output is sorted for columnisation (what bash will do), not a single line. You can quite easily sort the output alphabetically, though.

1

If you mean matching files, you may mean:

foo<TAB><TAB>

This should be an alternative:

ls | grep -E '^foo'

If you mean matching programs, you may do so for all directories in $PATH.

  • ls for every possible executable in $PATH, and then greping seems like a bad idea to me, YMMV – cat Jan 29 '16 at 0:32
  • When I hit TAB twice, I get Display all 6677 possibilities? (y or n), and my $PATH isn't even that cluttered. Seems slow to me, anyways. – cat Jan 29 '16 at 0:36

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