Homework / Exams - PowerPoint PPT Presentation

About This Presentation
Title:

Homework / Exams

Description:

... UNIX Shells / Processes / Shell Scripts. Homework #8 due class ... Often used instead of shell scripts, awk, sed. There are a2p and s2p translators available ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 17
Provided by: bobwi9
Learn more at: https://www.cs.umb.edu
Category:
Tags: exams | homework

less

Transcript and Presenter's Notes

Title: Homework / Exams


1
Homework / Exams
  • HW7 due today
  • Exam 3 next class
  • Covers Chapter 5 through end of Chapter 7
  • and Appendix B Standard Library
  • Plus UNIX Shells / Processes / Shell Scripts
  • Homework 8 due class 28
  • Review for Exam3

2
Shell Scripts
  • Yet another programming language! ?
  • Save a sequence of UNIX commands in a file
  • Three different script languages with their own
    syntax one for each type of UNIX shell! ?
  • C shell script file names have suffix .csh
  • File permission for execute must be set
  • chmod ux filename.csh
  • Then, type the filename at the UNIX prompt
  • filename.csh

3
C Shell Script Language
  • Builds on existing shell commands
  • Adds Expressions and Assignments
  • Adds comments, labels, and goto
  • Adds C-like Control Statements
  • foreach end
  • if then else endif
  • switch case endsw

4
C Shell Script Language
  • Assignment of expression value to variable
  • set a 3
  • set b 5
  • _at_ a a b
  • echo a a
  • Arithmetic only for integer variables

5
C Shell Script Language
  • Comment Syntax
  • is start of a comment to end of line
  • must be first character in file (for C shell
    script)
  • !/bin/tcsh ? Shebang gives path name to shell
  • Label Syntax
  • name Usually on a line by itself
  • goto Syntax
  • goto name

6
C Shell Script Language
  • Syntax for foreach end
  • foreach name (wordList)
  • use name as loop variable
  • end

7
C Shell Script Language
  • Syntax for if then else endif
  • if (expr1) then
  • list 1 shell commands
  • else if (expr2) then
  • list 2 shell commands
  • else
  • list 3 shell commands
  • endif

8
C Shell Script Language
  • Syntax for switch case endsw
  • switch (expr)
  • case pattern1
  • list shell commands
  • breaksw break out of this case
  • case pattern2
  • same as above
  • default
  • same as above
  • endsw

9
C Shell Script Example
  • blade64(26) pwd
  • /home/bobw/cs240
  • blade64(27) cat showhw.csh
  • showhw.csh ? AT LEAST 1 COMMENT LINE!
  • foreach subdir (hw1 hw2 hw3 hw4 hw5 hw6 hw7 hw8)
  • cd subdir
  • ls
  • cd ..
  • end

10
C Shell Script Example
  • blade64(28) showhw.csh
  • soln
  • reverse.in soln trim.in vt.in
  • bits.c bits.h buggy.c showbits.c
    soln
  • makefile soln
  • explore.c soln
  • alloc.c alloc.h alloctest.c makefile
    soln test.in
  • makefile mapss.c mapss.h soln
    testmapss.c
  • differ.in1 differ.in2 soln

11
C Shell Script Example
  • blade64(94) cat foo.csh
  • set a 3
  • set b 5
  • _at_ a a b
  • if (a gt b) then
  • echo a is greater than b
  • else
  • echo a is not greater than b
  • endif
  • blade64(95) foo.csh
  • 8 is greater than 5
  • blade64(96)

12
AWK Programs
  • Yet another programming language! ?
  • Authors Aho, Weinberger, and Kernighan
  • Invoke the awk utility with a program on a file
  • awk program defines operations to do on each line
  • blade64(43) cat awk1
  • BEGIN print "start of file ", FILENAME
  • print NF, 1
  • END print "end of file"

13
AWK Programs
  • blade64(44) cat foo.txt
  • Now is the time
  • for all good men
  • to come to the aid
  • blade64(45) awk -f awk1 foo.txt
  • start of file foo.txt
  • 4 Now
  • 4 for
  • 5 to
  • end of file

14
Perl Scripts
  • Yet another programming language! ?
  • Practical Extraction and Reporting Language
  • aka Pathologically Eclectic Rubbish Lister
  • Falls between a Shell script and a C program
  • Often used instead of shell scripts, awk, sed
  • There are a2p and s2p translators available
  • You can actually write O-O perl scripts!

15
Perl Scripts
  • blade64(46) cat test.pl
  • print "What is your name? "
  • chomp(name ltSTDINgt)
  • length length name
  • (length 3)? print "name has length
    characters.\n" die
  • blade64(47) perl test.pl
  • What is your name? Bob
  • Bob has 3 characters.
  • blade64(48) perl test.pl
  • What is your name? Robert
  • Died at test.pl line 4, ltSTDINgt line 1.

16
Review for Exam 3
  • The floor is now open for questions
Write a Comment
User Comments (0)
About PowerShow.com