2010-05-04 13:41:04 Updated lang(uage inspector)
An update to the "lang" command-line tool for quickly scanning what languages are available on a Unix system, though I've only tested it on a Mac, and it only seems to really work 10.5 and up. Comments, updates and suggestions welcome.

Available as a zip file download.

( sh )
  1  #!/bin/sh
2
echo
3
4 languages="clang gcc erl gfortran 8g 6g ghc java lua perl php python ruby macruby gem fscript"
5 websystems="apachectl ant rails"
6 databases="mysql sqlite3"
7 versionsystems="cvs git hg svn"
8 other="xcodebuild"
9 shells="bash csh ksh tcsh zsh"
10
11 for language in $languages echo $websystems echo $databases echo $versionsystems echo $shells $other
12 do
13
if [ `which $language` ]
14 then
15 case $language in
16
clang ) clang --version 2>&1 | head -n 1 | awk '{ print "Clang",$4 }';;
17 gcc ) gcc --version | grep gcc | awk '{ print "GCC",$3 }';;
18 erl ) erl +V 2>&1 | awk '{ print $1, $6 }';;
19 gfortran ) gfortran --version | grep GCC | awk '{ print "GFortran",$4 }';;
20 8g ) 8g -V | awk '{ print "Go",$3,"(32-bit)" }';;
21 6g ) 6g -V | awk '{ print "Go",$3,"(64-bit)" }';;
22 ghc ) ghc --version | awk '{ print $4, $8 }';;
23 java ) java -fullversion 2>&1 | sed 's/full version //' | sed 's/\"//g' | sed 's/java/Java/';;
24 lua ) lua -e 'print( _VERSION )';;
25 perl ) perl -version | grep 'is perl' | awk '{ print "Perl",$4 }';;
26 php ) php -v | grep PHP | grep built | awk '{print $1,$2}';;
27 python ) python -V;;
28 ruby ) ruby -v | awk '{ print "Ruby",$2 }';;
29 macruby ) /usr/local/bin/macruby -v | awk '{ print $1,$3,$4,$5; }';;
30 gem ) gem -v | awk '{ print "Ruby Gem",$1 }';;
31 fscript ) echo; echo "F-Script:"; fscript -v;;
32 apachectl ) apachectl -v | grep Apache | awk '{ print $3}' | sed 's/\// /';;
33 ant ) ant -version | awk '{ print $1,$2,$4 }';;
34 rails ) rails -v;;
35 mysql ) mysql --version | awk '{ print $1, $5 }';;
36 sqlite3 ) sqlite3 --version | awk '{ print "SQLite",$1 }';;
37 cvs ) cvs --version | grep client | sed 's/ (client\/server)//' | sed 's/ (CVS)//';;
38 git ) git --version | awk '{print $1,$3}';;
39 hg ) hg --version | head -n 1 | awk '{ split( $0,a," " ); print a[1],a[5] }' | sed 's/)//';;
40 svn ) svn --version | grep 'svn, version' | sed 's/, version//' | sed 's/svn/Subversion/';;
41 xcodebuild ) echo; xcodebuild -version | grep Xcode;;
42 bash ) bash --version | head -n 1 | awk '{ print "bash: ",$2, $4 }';;
43 csh ) csh --version | awk '{ print "csh: ",$1, $2 }';;
44 ksh ) ksh 'echo ${.sh.version}' | awk '{ print "ksh: ", $2, $3 }';;
45 sh ) sh --version | head -n 1 | awk '{ print "sh: ", $2, $4 }';;
46 tcsh ) tcsh --version | awk '{ print "tcsh: ",$1, $2 }';;
47 zsh ) zsh --version | awk '{ print "zsh: ",$1, $2 }';;
48 echo ) echo;;
49 esac
50 fi
51
done
52 echo
  • Jeff (Thu, June 24th, 2010, 11:35pm UTC)
    In case you're wondering, the above produces output like the following (on a system with many such languages installed):

    ( terminal )
      1  % lang
    2
    3 Clang 1.5
    4 GCC 4.2.1
    5 Erlang 5.7.5
    6 GFortran 4.2.3
    7 Go 5691 (64-bit)
    8 Haskell 6.10.4
    9 Java 1.6.0_20-b02-279
    10 Lua 5.1
    11 Perl v5.10.0
    12 PHP 5.3.1
    13 Python 2.6.1
    14 Ruby 1.8.7
    15 MacRuby 0.6 (ruby 1.9.0)
    16 Ruby Gem 1.3.5
    17
    18 F-Script:
    19 Architecture: x86 64bit
    20 F-Script Framework: 2.1
    21 fscript CLI: 2.2
    22 Regex Library: PCRE 7.8
    23
    24 Apache 2.2.14
    25 Apache Ant 1.7.1
    26 Rails 2.3.5
    27
    28 mysql 5.4.2-beta,
    29 SQLite 3.6.12
    30
    31 Concurrent Versions System 1.12.13
    32 git 1.6.3.1
    33 Mercurial 1.2.1
    34 Subversion 1.6.5 (r38866)
    35
    36 Xcode 3.2.3
    37
    38 %

  • Jeff (Tue, July 6th, 2010, 2:23pm UTC)
    Updated above to include shell information now.

    A note on those using this on older systems like my G4 Cube: I had to change line 13 to be these two lines:
    ( sh )
      1       w=`which $language | wc -w`
    2 if [ $w -eq 1 ]

    which is probably more general anyway. Also, the line about xcodebuild, for older systems, is written:
    ( sh )
      1            xcodebuild ) echo; xcodebuild -version | awk '{ print "xcodebuild: ",$3, $4 }';;

Leave a comment