You are on page 1of 16

Introduction to Scripting

Introduction

 Script is a program written for special


runtime environment that automate the
execution of tasks
 Scripting is the action of writing scripts using
scripting language
 Scripting languages are used to extend the
functionality of software
 Ex: enhancing web pages by providing dynamic
content
Need of Scripting

 They are designed to automate frequently


used task that usually involve calling or
passing commands to external program
 Example Scripting languages:
 PERL – Practical Extraction and Report Language
 PHP – Hypertext Preprocessor
 TCL – Tool Command Language
 Python
Scripts
 History
 Scripting languages gradually become more sophisticated
as computers began to time-share.
 In 1964, Pouzin gave a design for a more complex
command language, which he called a “shell”.
 This design was the inspiration for Thompson in the design
of the Unix shell in 1973.
 In the mid-1970’s, Bourne and Mashey separately added
control flow and variables; Bourne’s eventually became
the standard in Unix, called sh.
 Most common today is bash, the “Bourne-again” shell, but
others still exist: csh, tcsh, ksh, sh…
Origin of Scripting Languages

 Scripting languages originated as job control


languages
 1960s: IBM System 360 had the Job Control Language
 Scripts used to control other programs
▪ Launch compilation, execution
▪ Check return codes
 Scripting languages got increasingly more powerful
in the UNIX world
 Shell programming, AWK, Tcl/Tk, Perl
 Scripts used to combine components
▪ Gluing applications [Ousterhout, 97]
Origin of Scripting
 The Unix OS developers coined the term shell script for
sequence of commands that were read from a file and
followed in sequence
 Script is a file that is intended to be executed directly
rather than being compiled
 Examples of scripts with respect to unix system are:
 AWK: this utility reads the standard input line by line and takes
an action on part of entire line
 Perl: is a scripting language developed by Larry Wall, especially
designed for text processing
▪ It stands for Practical Extraction and Report Language
▪ It runs on a variety of Operating Systems
System Programming Languages

 System programming languages replaced assembly


languages
 Benefits:
▪ The compiler hides unnecessary details, so these languages have a
higher level of abstraction, increasing productivity
▪ They are strongly typed, i.e. meaning of information is specified before
its use, enabling substantial error checking at compile time
▪ They make programs more portable
 SPLs and ALs are both intended to write application from
scratch
 SPLs try to minimize the loss in performance with respect to ALs
 E.g. PL/1, Pascal, C, C++, Java
Scripting Vs. Programming

 Scripts are interpreted. It means they are


processed from scratch every time you run
them
 Programs are executed
Common Characteristics:

 Both batch and interactive use


 While a few languages (e.g. Perl) have a compiler
that requires the entire source program, almost all
scripting languages either compile or interpret line
by line
 Many “compiled” versions are actually completely
equivalent to the interpreter running behind the
scenes (like in Python).
Common Characteristics:
 Economy of expression
 Two variants: some make heavy use of punctuation and
short identifiers (like Perl), while others emphasize
“English-like” functionality
 Either way, things get shorter. Java versus Python (or
Ruby or Perl):
class Hello {
public static void main(String[] args) {
System.out.println(“Hello, world!”);
}

print “Hello, world!\n”


Common Characteristics:
 Lack of declarations; simple scoping rules.
 While the rules vary, they are generally fairly simple
and additional syntax is necessary to alter them.
▪ In Perl, everything is of global scope by default, but
optional parameters can limit the scope to local
▪ In PHP, everything is local by default, and any global
variables must be explicitly imported.
▪ In Python, everything is local to the block in which the
assignment appears, and special syntax is required to
assign a variable in a surrounding scope.
Common Characteristics:
 Flexible dynamic typing
 In PHP, Python and Ruby, the type of a variable is only
checked right before use
 In Perl, Rexx, or Tcl, things are even more dynamic:
$a = “4”
print $a . 3 . “\n”
print $a + 3 . “\n”
Outputs the following:
43
7
Common Characteristics:

 Easy access to other programs


 While all languages provide support for OS
functionality, scripting languages generally provide
amazing and much more fundamental built-in
support.
 Examples include directory and file manipulation,
I/O modules, sockets, database access, password
and authentication support, and network
communications.
Common Characteristics:

 Sophisticated pattern matching and string


manipulation
 Perl is perhaps the master of this, but it traces back
to the text processing sed/awk ancestry.
 These are generally based on extended regular
expression (which we already saw a bit of when
using lex at the beginning).
Common Characteristics:

 High level data types


 In general, scripting languages provide support for
sets, dictionaries, lists and tuples (at a minimum).
 While languages like C++ and Java have these, they
usually need to be imported separately.
 Behind the scenes, optimizations like arrays indexed
using hash tables are quite common.
 Garbage collection is always automatic, so user
never has to deal with heap/stack issues.
Scripting Today
 Scripting allows application to be developed much faster
than traditional methods allow.
 We use it to manipulate, customize, automate the facilities
of existing system
 Ex: Use of client side scripting and Dynamic HTML to create
interactive and feature rich enhanced web pages
 Using SL with its rich functionality
 Ex: these are used by UNIX admin for system maintenance work,
like managing user permissions
 Windows system admin adopt Perl for their work
 Apache web server has an embedded Perl interpreter for
CGI scripts

You might also like