1 / 16

Homework / Exams

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 Exam#3. Shell Scripts. Yet another programming language! 

mpam
Télécharger la présentation

Homework / Exams

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 Exam#3

  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 u+x 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 @ 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 @ a = $a + $b if ($a > $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 = <STDIN>); $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, <STDIN> line 1.

  16. Review for Exam #3 • The floor is now open for questions

More Related