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

Info iconThis preview shows pages 1–9. 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
Background image of page 1

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

View Full DocumentRight 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
Background 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
Background image of page 3

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

View Full DocumentRight 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
Background 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
Background image of page 5

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

View Full DocumentRight 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
Background 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/15/2010 for the course CS 2024 taught by Professor Dinapoli during the Fall '07 term at Cornell University (Engineering School).

Page1 / 31

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

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online