Skip to content

Output --version for all executables of a given name

The output of which -a ruby ends up being a path per line for every 'ruby' executable found within the user's PATH. This is an excellent type of output to pipe into another command—or series of them.

which -a ruby | while read line; do echo $line; echo `$line --version`; done

If that code were expanded out it would look like:

while read line;
do
	echo $line;
	echo `$line --version`;
done

Sadly this is basically my first attempt to use piping in any meaningful way.