Scripting Languages
Originally, a script was a file containing a sequence of commands that needed to be executed Control structures were added to make it possible to do more with scripts
Characteristics of Scripting Languages Generally interpreted Dynamic typing - no declarations Make text processing easy Often provide pattern matching for strings Provide file and directory manipulation Make it easy to do things quickly
Basic Scripting Languages Unix and Linux come with shell programs which are programmable –sh –bash –ksh –csh DOS had BAT files
Scripting in Other Environments Even with a GUI operating system, it is still useful to be able to automate repetetive tasks –Windows still has bat files –Mac OS has AppleScript Some applications have a scripting language built into them –Microsoft applications have Visual Basic for Applications (VBA) –Hypercard (Apple) had HyperTalk
Other Scripting Languages Other scripting languages were developed to provide increased capability –sed -- adapted from the unix ed editor in 1977 –AWK -- created by Ajo, Wienberger and Kernighan in 1977 –Tcl -- an extensible scripting language written by John Ousterhout in 1987 –Perl -- created by Larry Wall in 1986 –Python-- created in 1989 by Guido van Rossum –Ruby -- created in 1993 by Yukihiro Matsumoto
Scripting and the Web More recently, a number of scripting languages have been developed for use with web browsers –PHP –JavaScript –ASP (part of Microsoft.NET framework)
Scripting on onyx the shell command languages perl python ruby tcl
Scripts on onyx In the following, is the name of the interpreter (perl, python, ruby, tcl) create a file - a script whose first line is #!/usr/bin/ There are man pages for all of these man
Running Scripts two ways to run a program –give the name of file containing script to the interpreter prog –make script file executable and type the program name chmod +x script script./script
Hello World Perl #!/usr/bin/perl print "Hello, world!\n"; Python #!/usr/bin/python import sys sys.stdout.write("Hello world!\n")
Hello World Ruby #!/usr/bin/ruby print "Hello world!\n" Tcl #!/usr/bin/tcl puts "Hello world!"
Input Redirection In Linux, you can redirect the contents of a file into your program using the < operator. The command doCommand < infile will send the contents of infile to your program as if it were coming from the keyboard.
Input/Output Redirection Similarly, you can use the > operator to send the console output from your program into a file. doCommand > outfile You can do both operations at the same time with doCommand outfile