Scripting languages allow the system manager to run sequences of predefined tasks without having to sit and run each task by hand, one by one. You usually want to write a script for one of two reasons:
Each command takes a while to run and it's tedious to sit and wait before typing the next command.
The sequence of commands being run would be run several times (for example, as a weekly or daily job) which would make it tedious to perform manually every time.
In this RTFM, we'll look at the common scripting languages available to Windows and Linux/Unix users, with some of the pros and cons of each.
The grey area
The four scripting languages we've chosen are likely to generate outrage among some community members, because (a) everyone has their own favourite; and (b) there's a grey area where it's hard to decide whether something is a scripting language (a means of automating relatively simple steps) or a fully-blown programming language.
It's fairly clear to us, for example, that a Windows batch file would generally be referred to as a script, not a program, as would a Unix shell script. VBScript, on the other hand, although often used as a scripting language, is nigh on identical to the programming language used by ASP Web developers, so it might be fair to class it as a programming language. Similarly with Perl: although it started life with the intention of being a simple mechanism for extracting data from files and producing report-like output, it's grown into something that could be regarded as a programming language.
Our definition of a scripting language, then, is: something that, in our experience, is frequently used by system managers to automate system-related jobs. If you think we've maligned Ruby, or Tcl, or Python, or whatever your favourite "scripting" language happens to be, let us know in the forums.
DOS/Windows batch files
This is the daddy of PC-based scripting languages, and is as old as DOS itself. DOS batch files follow a very basic flow, and have the ability to do simple loops, IF … THEN statements and use GOTO statements to jump between the various bits of code that may or may not need to be run depending on the conditions in the IF statements.
Because they use the same syntax as you can use on the command line in a DOS window, they can run any command that you could execute from the command line - copying files, reading and writing files, even executing the command-line version of a third party program that's been installed.
It only takes a few minutes to get to grips with the language of batch files, and if all you want to do is basic file manipulation and execution of command-line programs, they're the quickest way to provide automation in DOS or Windows.
As we've said, VBScript is in fact a very powerful language, and it permits a higher level of integration between the script and the computer system. It's a more complex language to get to grips with than the batch file syntax, and as such the learning curve for getting something basic working is steeper (it's far easier to read, write or copy a file in a batch file than in VBScript, for example, since in the latter you have to faff about with file objects and input/output streams) but at a higher level it's much more flexible - mainly because it can instantiate and use COM objects. So with VBScript it's child's play to, for example, run a query using an ADODB database object, or send an email message to a system manager based on what the script has found using a CDONTS messaging object. Unlike DOS batch files, VBScript includes features such as functions and procedures, so you're not stuck with having a rat's nest of GOTO statements controlling the flow of the script.
VBScript has a BASIC-like language that is easy to learn, and has advanced features such as database/email access and the ability to instantiate any Windows-standard or third party COM object to do complex stuff; for basic file copying and read/write operations, though, a batch file may be simpler.
Unix shell scripts
The shell script is Unix's alternative to the DOS batch file - except, as you might expect with Unix, its syntax is way more complicated. The features are similar to those of the batch file, though - IF statements, basic flow control, and the ability to execute any standard command or third party executable to which the user under whose ID the script is executing has access. As with DOS, the shell script can run any command that you'd be able to run from the command line.
There's only one problem with Unix shells: there are loads of different ones, each of which has its own esoteric tweaks. There are two main families, though: the Bourne shell ("sh") and the C shell ("csh"), and each the shedloads of other shells that are available is based on one of these ("bash" is a derivative of "sh", for example, while "tcsh" comes from "csh"). Generally speaking, most built-in system scripts are written in for the "sh" family, but the "csh" language is more comprehensible for non-programmers.
Unix shell scripts, then, are powerful but are generally limited to basic flow control, file access and system command execution.
Perl is the most commonly used Unix scripting language for those who want more than shells can provide them. Like VBScript, Perl has evolved over the years into something that allows you to do things like accessing databases, doing DNS lookups, requesting Web pages and such like in just a few lines of code - and like VBScript on Windows, it provides much better flow control than the shell script in the form of functions and procedures.
Unlike VBScript, though, Perl isn't a part of the operating system itself. This said, though, it's hard to find a flavour of Unix or Linux that doesn't come with Perl installed as standard, which in practice makes it as accessible to Unix people as VBScript is to Windows people.
Perl's additional functionality comes at a price, though: namely that it's a bit harder to get started with than basic shell scripting.
|DOS batch files||No||Built-in|
|Perl||Via add-on software (which comes as standard with some Unix/Linux implementations)||Via add-on software|