Scripting Languages CS351 – Programming Paradigms.

Slides:



Advertisements
Similar presentations
Introduction to Python. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
Advertisements

What is a scripting language? What is Python?
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
Scripting Languages CS351 – Programming Paradigms.
SCRIPTING LANGUAGE. The first interactive shells were developed in the 1960s to enable remote operation of the first time-sharing systems, and these,
Scripting Languages CS 351 – Programming Paradigms.
Scripting Languages. Originally, a script was a file containing a sequence of commands that needed to be executed Control structures were added to make.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
1 Day 16 Sed and Awk. 2 Looking through output We already know what “grep” does. –It looks for something in a file. –Returns any line from the file that.
Advanced File Processing
Introduction to Shell Script Programming
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Introduction to Python John Reiser May 5 th, 2010.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Significance of Scripting Languages for Operating System Administration Vladimir Mateljan Željka Požgaj Krunoslav Peter INFuture2007.
Linux+ Guide to Linux Certification, Third Edition
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Sed, awk, & perl CS 2204 Class meeting 13 *Notes by Mir Farooq Ali and other members of the CS faculty at Virginia Tech. Copyright 2003.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Introduction to Unix – CS 21
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
CS 598 Scripting Languages Design and Implementation 1. Introduction 1.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
Chapter Six Introduction to Shell Script Programming.
PHP vs. Python. Similarities are interpreted, high level languages with dynamic typing are Open Source are supported by large developer communities are.
Week Four Agenda Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
Linux+ Guide to Linux Certification, Second Edition
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
By Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Programming Languages Meeting 12 November 18/19, 2014.
Linux Administration Working with the BASH Shell.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
COMP075 OS2 Bash Scripting. Scripting? BASH provides access to OS functions, like any OS shell Also like any OS shell, BASH includes the ability to write.
CSE 374 Programming Concepts & Tools
The language focusses on ease of use
CIRC Winter Boot Camp 2017 Baowei Liu
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
CSC 352– Unix Programming, Fall 2012
Henning Schulzrinne Advanced Programming
What is Bash Shell Scripting?
Guide To UNIX Using Linux Third Edition
More advanced BASH usage
Linux Shell Script Programming
CSC 352– Unix Programming, Fall, 2011
Introduction to Bash Programming, part 3
Presentation transcript:

Scripting Languages CS351 – Programming Paradigms

Common Characteristics of Scripting languages. 1. Both Batch and Interactive use. 2. Economy of Expression. 3. Lack of declarations; simple scoping rules 4. Flexible dynamic typing. 5. Easy access to other programs. 6. Sophisticated Pattern matching. 7. High-level data types.

1 – Batch and Interactive Use Perl has a JIT compiler that reads the entire program before execution. Other languages are quite happy to only execute a line as soon as it has been read. Python, Tcl and Ruby will also accept commands from the keyboard.

2 – Economy of Expression To support rapid development and interactive use, scripting languages require very little boilerplate code. This can be illustrated very clearly by the following example: public static void main(String args[]) { System.out.println(“Hello!”); } print “Hello!\n” Another example is reading a file word by word.

3 – Lack of Declarations and simple scoping rules Most scripting languages dispense with declarations. They also use simple rules to govern the scopes of names ( identifiers ). In Perl every name is global by default. In Tcl and PHP, everything is local by default. Python has a unique implementation in that any variable that is assigned a value is local to the block in which the assignment appears. Special syntax is required to access the variable from a surrounding scope.

4 – Flexible Dynamic Typing Most scripting languages are dynamically typed. In PHP, Ruby and Python, the type of a variable is checked immediately prior to use. In others such as Tcl and Perl, a variable can be interpreted differently in different contexts. E.g. $a = “4”; print $a. 3. “\n”; print $a + 4. “\n”;

5 – Easy access to other programs Most programming languages provide a way to interact with the underlying commands of the OS. However this can be quite convoluted, as anyone who has had to do work with the Runtime.exec command knows. Scripting languages support these OS commands and their outputs much more cleanly and directly. Perl provides 100 built-in commands for the OS while the os module in Python is an excellent library for executing commands.

6 – Pattern Matching As scripting language ancestors were used for text processing, the support for pattern matching in text files is impressive. Scripting languages have very good facilities for pattern matching, searching and string manipulation. This is all based upon the notion of extended regular expressions. sed is a very powerful scripting language for text processing. What does sed '1!G;h;$!d' do?

7 – High level data types High level data types such as sets, bags, dictionaries, lists and tuples are some of the very convenient features provided by scripting languages. In C++, it is possible to use ``operator overloading’’ to create advanced user-defined types but scripting languages go one step further by building high-level types into the syntax and semantics. E.g. in Python a dictionary can map a key to a value: dict([(x, x**2) for x in (2, 4, 6)]) {2: 4, 4: 16, 6: 36}

Scripting Languages Evolution Due to the dynamism of the open source community and the freedom from working within an ISO published standard, scripting languages have been at the recent forefront of programming language development. Most scripting languages have had only a single person driving the initial development. All of the most interesting features and powerful features appear in Python: E.g. true iterators, array slices, multiway assignment, anonymous first-class functions and functional type lists.

Problem Domains for Scripting Languages Some languages such as Perl, Python and Ruby are intended for general purpose use as they support features such as modules, separate compilation, reflection etc. However a lot of scripting languages are intended for use within a well defined domain. We will look in detail at the following: 1. Shell Languages 2. Text Processing 3. Glue Languages

Shell Languages In the early 1970’s a command language for automating the control of Unix programs was written. This was known as ``shell’’ or sh. This was extended to allow for variables and control flow and was known as bash. This is the default Unix command shell. Shell languages allow for many operations including manipulating file names, arguments and commands and for tying other programs together.

Shell Languages cont… Some features provided by a shell languages. List all file ending in.txt -> ls *.txt This feature is known as filename expansion or globbing. There are other alternatives to this command: ls fig?.eps ls fig[0-9].eps ls fig3.{eps,pdf} What do each of these commands do?

Shell Languages cont… Such simple commands do not even hint at the flexibility provided by shell languages. It is possible to provide loops within shell languages. These can be very useful. E.g. for file in *.eps do ps2pdf $file done What is going on here?

Shell Languages cont… We can also use conditionals within our bash scripts: for file in *.eps do if [ ! test –e ${file%.eps}.pdf ] then ps2pdf $file fi done The test command has many features, type man test to get a list of them all.

Shell Languages cont… It is possible to pass the results of one program as the input to another very easily through the use of pipes. find. –name *.txt | ls | wc –l What does this do? It is is also possible to send output to and from files using re- directs. ls *.txt > files for file in *.txt; do echo $file >> files; done What do these commands do?

Shell Languages cont… There are some simple rules to bear in mind when using shell scripts. foo=bar single=‘$foo’ double=“$foo” echo $single $double What is printed? When using other programs in a shell script, they must be placed within backticks. bname=`basename $file.txt`

Text Processing Shell languages are heavily string oriented. Commands are strings parsed into single words. All variables are string-valued and there are elaborate quoting conventions. However shell languages cannot be used like a text editor. How can we account for interactive features such as insertion, deletion, replacement, bracket-matching etc. Through the use of special ``online’’ editors such as sed and awk.

sed Stands for stream editor. Very powerful and can be used to write complex scripts but is more commonly used for one-line programs. E.g. sed –e ‘/^[[:space:]]*$/d’ awk is an attempt to modify sed to look more like a programming language.

Glue Languages These general purpose scripting languages inherit a rich set of features form both the shell languages and the text processing languages. Imagine writing a script to kill a named process in *nix. We could do it ( hack it ) via a bash script or we could use a general purpose language to do it. We will discuss Python in detail on Thursday.