In a typical Linux shell (bash) it is possible to to hit tab twice, to get a list of all available shell commands.
Is there a command which has the same behaviour? I want to pipe it into grep
and search it.
In a typical Linux shell (bash) it is possible to to hit tab twice, to get a list of all available shell commands.
Is there a command which has the same behaviour? I want to pipe it into grep
and search it.
An answer got deleted, I liked it most, so I'm trying to repost it:
compgen is of course better
I found this to be the most typical shell thing, I think it works also with other shells (which I doubt with things like
IFS=':'
)Clearly, there maybe problems, if the file is not an executable, but I think for my question, that is enough - I just want to
grep
my output - which means searching for some commands.You could use compgen. For example:
You also could grep it, like this:
Source: http://www.cyberciti.biz/open-source/command-line-hacks/compgen-linux-command/
There may be things on your path which aren't actually executable.
This will also print paths, of course. If you only want unqualified filenames, it should be easy to adapt this.
Funny, StackOverflow doesn't know how to handle syntax highlighting for this. :-)
Bash uses a builtin command named 'complete' to implement the tab feature.
I don't have the details to hand, but the should tell you all you need to know: