New Location

My website has moved to http://www.jasonwhaley.com. Please visit there for the latest and only remain here for legacy content.

Monday, November 23, 2009

compgen -c

Bash has a built-in called compgen that is responsible for tab completion when using the bash shell. compgen has some nifty arguments you can use. For instance, to get all of the executables on your path sent to stdout, it's just a matter of running
compgen -c [$beginningCharacters]
This is useful in cases where you need to programmatically see what executables are available in $PATH. For instance, if you remember part of the name of an executable, but not what characters the executable begins with, you can pipe compgen -c out and grep for a string you know exists.

Nifty stuff.

0 comments: