Prev - Index - Next

From shells scripts to interpreters to compilers and back again

A computer without COBOL and Fortran is like a piece of chocolate cake without ketchup and mustard.

Linux is well supported by a wide variety of free and commercial implementations of a large number of programming languages, including:

Ada, Assembler, AWK, BASIC, C, C++, Caml, CLisp, Dylan, Eiffel, Erlang, Forth, Fortran, Gofer, Guile, Haskell, Icon, Intercal, Java, Lua, Lisp, Mercury, Modula-2, Modula-3, Oberon, Objective C, Pascal, Perl, Pike, Postscript, Prolog, Python, REXX, Sather, Scheme, sh, Simula, Smalltalk, SQL and Tcl.

And this does not even touch the surface - there are language variants, there are maths tools that could be included, such as Matlab and Yorick; there are shells such as bash, scsh and zsh which offer advanced scripting functionality; and a vast array of obscure academic languages.

In addition to these, are the various shells, such as bash, tcsh, esh and zsh, which support a range of programming constructs.

Of the languages listed above, only a handful are widely used today for Linux/Unix systems and applications development:

Here are some brief observations on those that I use (the C/C++ language gets a page to itself):


Java is a far nicer object-oriented version of C than C++ could ever hope to be, especially with the injection of Smalltalk concepts.

Java offers a number of attractive advantages over both C and C++ with a high degree of platform independence, a small language definition and standard extension libraries.

However, Java is currently suffering from a few drawbacks:

  1. The language is driven by one company, with commercial interests, rather than an international standards committee (some would argue this is an advantage!)

  2. The language and associated libraries are constantly being developed, causing developers to constantly play 'catch-up'.

  3. The Linux Java development kit (JDK) lags well behind the officially supported JDKs for Windows and Solaris (although this is improving).

  4. Hype.


Perl is often described as the Swiss Army knife of system administrators. Over the years, Perl has evolved from a super-AWK for text processing to a fully-fledged object-oriented programming language which is probably best known as a CGI scripting language.

Perl is ideal for text processing, handling files, manipulating processes, formatted reporting and CGI scripting. Like Python, it is an excellent solution to jobs that are too tedious for C and too complex for shell scripts.

Perl is very flexible, but the often arcane syntax has led to accusations of it being a 'write-only' language; with care, Perl scripts are easily read and maintained.

Here are some examples of Perl scripts: a random signature file generator and a filter that strips hostnames from stdin (eg. a Netscape bookmarks file).

There are a number of Perl FAQs and also Perl documents online.


Eric Raymond advises new hackers to learn four languages: C, Perl, Python and Lisp, and he argues that the best of these languages to learn first is Python. Why?


Python has a very active development community, mailing lists, special interest groups, a newsletter, two newsgroups and at least four text books.

The only disadvantage to beginners is the indentation system, but after a short while, I found that it was actually a real advantage, and after years of C and Perl hacking, I rarely touch Perl now and use Python in preference to C for most of my work.

Here are some small examples of Python: a MD5 file tool and a script that interrogates a news server via NNTP.

Python comes with extensive documentation and a large number of standard libraries, but there is also an archive of third party libraries and Python documentation & FAQs.


Scheme is a relation to Lisp, and is used extensively in academic research. It is also often used as an extension language due to the relatively small size of a Scheme interpreter implementation.

Scheme offers a very logical language with a small definition, but it also requires a very different mindset that a structured programmer who uses C or Pascal would find rather alien. It should be noted that Scheme (and Lisp) programs often have a beauty in their structure and design!

A very simple example of Scheme's functional style, with recursion is:

    ;; define a Fibonacci calculator
    ;; and then calculate Fibonacci (12) & display the value

    (define (fib x)
      (if (< x 2)
	(+ (fib (- x 1)) (fib (- x 2)))))

    (display (fib 12))

Scheme interpreters such as SCM come with very comprehensive libraries (eg. SLIB) that support Unix systems programming, CGI scripting, socket I/O and a curses interface, and there are also some excellent Scheme compilers and Scheme->C converters.

One well known example of embedded SCHEME is the GIMP, which uses SIOD (a Scheme interpreter) for the ScriptFu scripting extension.

GUILE is the GNU Project's Scheme-based extension language and is a direct result of Richard Stallman's distaste of Tcl! GUILE is used as an extension language for a number of projects, including the SCWM, the Scheme configurable window manager.

While GUILE is still in development, it is very stable, but lacks useful documentation at this point in time.

Shell scripting

Where does shell scripting end and programming begin? What is the difference between an esh shell script and a GUILE program? Is it just a question of semantics?

There are a number of good shell scripting tutorials on the web including "How to write a shell script".


Tcl (the Tool Command Language) was designed as an extension language for large software projects, rather than a stand-alone language. As one example, until version 8, it had only one data type: the string. Like Perl, it has suffered from additional features being grafted onto each version, cluttering the language.

Tcl's greatest strength is the X11 toolkit, Tk, which allows the creation of graphical programs in a very simple fashion (compared to other toolkits like Athena, Gtk or Motif).

However, these days, most other languages, including Perl, Python and Scheme have Tk interfaces (Tk/Perl, Tkinter and STk respectively), which provides the simple X11 interface without the limitations of Tcl.

When compared with Perl and Python, Tcl also suffers from a lack of (up to date) documentation and useful support libraries.

Here is a simple X11 "more" clone in forty lines of code. An equivalent program using C and the Athena or Motif widget sets would take hundreds of lines of code.

Some parting thoughts on languages

  1. Learn a few different languages.
    The different paradigms force you to think in different ways which extends you as a problem solver and programmer

  2. There is no one definitive language.
    Different languages have advantages and disadvantages and are rarely appropriate for every software project: would you write a CGI script in assembler or a kernel driver in Scheme?

  3. Understand tradeoffs.
    If you can write a 25 line Perl script in 2 minutes that will parse a text file, collate the output and send a formatted report to a Postscript printer, is there any point in writing an equivalent 450 line C program in 5 hours that runs ten times as fast if it is only going to be used twice?

Prev - Index - Next