lecture10

lecture10 - More Handy Shell Features Control Flow and...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: More Handy Shell Features Control Flow and Loops Functions Lecture 10: More Bash Scripting CS2042 - UNIX Tools October 22, 2008 Lecture 10: Scripting, cont. More Handy Shell Features Control Flow and Loops Functions Arithmetic Arrays Lecture Outline 1 More Handy Shell Features Arithmetic Arrays 2 Control Flow and Loops Case and Select While Loops For Loops 3 Functions Breaking Up a Script Local vs. Global Vars Lecture 10: Scripting, cont. More Handy Shell Features Control Flow and Loops Functions Arithmetic Arrays Basic Operators While shell scripts are usually used to automate more complex tasks, occasionally a little arithmetic comes in handy. Here is a partial list of operators that you can use: Syntax: Meaning: a++, a-- Post-increment/decrement (add/subtract 1) ++a,-- a Pre-increment/decrement a+b, a-b Addition/subtraction a*b, a/b Multiplication/division a%b Modulo (remainder after dividing) a**b Exponential a > b, a < b Greater than, less than a==b, a!=b Equality, inequality =, +=, -= Assignments Lecture 10: Scripting, cont. More Handy Shell Features Control Flow and Loops Functions Arithmetic Arrays Using Arithmetic Expressions There are two good ways to use arithmetic: as its own operation using variables, or in an expansion as part of a larger command. The “Let” Built-In let VAR=$1+15 Evaluates all following expressions It is generally good form to use the $[ EXPRESSION ] syntax to perform arithmetic expansions. Note that this only calculates the result of EXPRESSION, and does no tests. Example: echo $[ 323*17 ] 5491 Lecture 10: Scripting, cont. More Handy Shell Features Control Flow and Loops Functions Arithmetic Arrays Lecture Outline 1 More Handy Shell Features Arithmetic Arrays 2 Control Flow and Loops Case and Select While Loops For Loops 3 Functions Breaking Up a Script Local vs. Global Vars Lecture 10: Scripting, cont. More Handy Shell Features Control Flow and Loops Functions Arithmetic Arrays Defining Arrays An array is a variable containing multiple values. There are three different ways to create an array: Declaring an Array declare -a arrayname Explicit declaration, empty until modified arrayname[index number]=value Puts value in the specified position of a new array arrayname=(value1 value2 ... valueN) Creates an array using the given values, indexed sequentially Lecture 10: Scripting, cont. More Handy Shell Features Control Flow and Loops Functions Arithmetic Arrays Accessing Arrays...
View Full Document

This note was uploaded on 01/23/2009 for the course CS 2042 taught by Professor Mccourt during the Fall '08 term at Cornell.

Page1 / 23

lecture10 - More Handy Shell Features Control Flow and...

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

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