Yesterday I picked up a book on a writing compilers and interpreters. This particular book’s code is written in Java. It’s been a while since I’ve coded in Java and I had no idea what Java dev tools I had on my system. So I created a simple hello world Java class and ran javac Main.java
and java main
and got the result I was hoping for. Yay! Then I figured I’d check what version of Java I had installed. So I did what I thought was obvious:
java -v
Unrecognized option. Oh, I know some language uses a capital V instead. Must be Java.
java -V
Nope. OK. I guess I just have to use the long version.
java --version
No luck. All right. We’ll just start going through every possible iteration…
java --Version
java -Version
java -version
Finally! That last one told me I had version 1.8.0_262.
It got me thinking that finding the version of various tools and programs is something you have to do now and then and I rarely get it right on the first try. Some other examples:
gcc --version
node -v
python -V
perl -v
go version
lua -v
rustc --version
Then I got to thinking that it would be pretty easy to write a utility script to capture a bunch of this stuff. Here’s the meat of what I did, just capturing a few of the above examples:
case $1 in java) $1 -version ;; gcc | rustc) $1 --version ;; node | perl | lua) $1 -v ;; esac
I fleshed it out a bit, added a bunch more programs to it, threw it up on github and tweeted about it. I’ve already had a couple of PRs adding additional tools to it. Hoping to get some more. As of this writing, it can recognize 36 different programs. It checks to see if you have the program installed at all before trying to find its version, and displays a message if it doesn’t yet know about the program you are checking. Also supports a -h
version for help, -c
to display the count of how many programs it recognizes, and of course -v
for displaying its own version.
And yes, it can be used to check its own version “recursively”!
version version
If it sounds useful, grab it here:
https://github.com/bit101/version
Just put the version
script somewhere in your path and you should be good to go. You can add whatever other tools you use to pretty easily. If you do, I’d love to know about them, either through a PR or just let me know the tool and how you find the version.
I’ve only actually tested it on a couple of Linux machines. It should work on Mac as well, but I’ve got to put in the time to test it later today.
One thought on “Introducing “version””