{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs2042_Lecture9

cs2042_Lecture9 - CS2042 Unix Tools Fall 2009 Lecture 9...

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2042 - Unix Tools Fall 2009 Lecture 9 David Slater dms236 at cornell.edu October 19, 2009 David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Organization Homework 3 due Wednesday at 11:59 pm. Correction: If you have more than 9 parameters, you refer to them as $ { 10 } , $ { 11 } and so on. Homeworks 1 and 2 are graded (for everyone who didn’t email it to me) David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 2
Some Review What does this do? #! /bin/bash gawk ’$1 = "’$1’" { count++ ; print $2 } END { print count } ’ infile David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Some Review What does this do? #! /bin/bash gawk ’$1 = "’$1’" { count++ ; print $2 } END { print count } ’ infile Prints the second field whenever the first matches the first argument and then prints the total number of matched lines. David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 4
Arithmetic A little arithmetic can be useful and BASH can perform all the standard operators Arithmetic a++, a– : Post-increment/decrement ++a, –a : Pre-increment/decrement a+b, a-b : Addition/subtraction a*b, a/b : Multiplication/division a%b : Modulu a**b : Exponential a¿b, a¡b : Greater than, less than a==b, a!=b : Equality/inequality =, +=, -= : Assignments David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Using Arithmetic Expressions We have already seen one way to do arithmetic: Example: echo $((2+5)) 7 We can also use it as part of a larger command: The ”Let” Built-In VAR1=2 let VAR2=$VAR1+15 let VAR2++ echo $VAR2 18 let evaluates all expressions following the equal sign David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 6
The Difference There are two major differences: all characters between the (( and )) are treated as quoted (no shell expansion) The let statement requires there be no spaces anywhere (so need to quote) Example: let "i=i + 1" i=$((i + 1)) David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Loopy loops! The while loop while cmd do cmd1 cmd2 done Executes cmd1, cmd2 as long as cmd is successful (i.e. its exit code is 0). David Slater dms236 at cornell.edu CS2042 - Unix Tools
Image of page 8
While loop example i="1" while [ $i -le 10 ] do echo "$i" i=$(($i+1)) done This loop prints all numbers 1 to 10.
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern