Tuesday, May 3, 2011

SCRIPTING LANGUAGES

Today there is a large set of programming languages collectively referred to as scripting languages.
The original idea of a “script” was a set of operating system commands placed in a file. When a user “executes”
the script file, the set of commands in the file is executed in order. This notion of a script is still heavily used.
Scripts are very useful for automating routine tasks which otherwise would require a person to sit at a keyboard
and type the same commands again and again.
Here is an example from the author’s experience. This script is for a Unix computer. The script runs a grading
program against an output file for a student’s project, then runs the student’s original program against a smaller
“extract” file as a second test, and finally prints a set of documents for the student. The script automates the
execution of a set of commands by accepting a set of parameters in the command line, and then using the values
of those variables to construct the appropriate commands and execute them. When using the script, the user
types “gradeP” followed by six character strings giving the name of the student’s output file, the comments file
to be created, etc., and at last the student’s name:

#! /bin/sh
# Script gradeP for grading the access_log projects
# Variables:
# $1 student’s output file
# $2 comments/grading file to be created by
# program gradeProj.pl
# $3 student’s source code
# $4 access_log_extract-report
# $5 path to student’s directory
# $6 Name
# Run the grading program against the student’s output file
gradeProj.pl $6 $5$1 $5$2
# Test the student’s program against the extract file
$5$3 /home/fac/chr/public_html/plc/access_log_extract $5$4
# Print the results
nenscript -2 -r $5$2 $5$1 $5$3 $5$4
This script is a script in the Bourne shell (command interpreter) for Unix, and it flexibly executes a
set of commands that otherwise would require much more typing and be much more prone to errors of
execution.
The first line, the one beginning with #! (called a shebang), tells Unix to execute the commands in the file
using the program sh, also known as the Bourne shell. The lines beginning with # are comment lines. The
remaining lines are commands whose parameters are constructed from the variables defined by the original
command line arguments.
The Bourne shell scripting language is one of many scripting languages one can categorize as job
control language (JCL) scripting languages. Others include the C shell (csh), the Korn shell (ksh), Bash (Bourne
Again SHell), JCL and JES2 (IBM’s languages for mainframes), and MS-DOS Batch. They are all similar
in that they can accept a file of commands as input, incorporate values of parameters available at execution
time, and execute the sequence of commands. Except for JCL and JES2, they all have limited programming
controls as well, and include conditional expressions and the ability to loop and branch during execution of the
command file.
Here’s an example MS-DOS Batch file that will copy a list of files to a directory called DUPLICAT. Lines
beginning with twin colons are comment lines. Lines beginning with a single colon are “labels” referred to by
other statements. Note the conditional statement that creates the directory only if it does not already exist. Also
note the looping structure using the GOTO statement with the COPY-FILES label.

No comments:

Post a Comment