Lecture 2

Lecture 2 - 1/16/11 ECE364: Software Tools Laboratory...

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

View Full Document Right Arrow Icon
1/16/11 1 ECE364: Software Tools Laboratory Lecture 2 January 17, 2011 Lecturer: Michael Goldfarb 1 Lecture 2 Summary § More KornShell Basics § I/O Redirection and Pipes § Quotes in KornShell § Capturing Command Output § Basic Regular Expressions § Commands: grep, cut, paste, and wc 2
Background image of page 1

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

View Full DocumentRight Arrow Icon
1/16/11 2 Arrays in KornShell § Declaring an array: Arr=(1 2 3 4 foo) § Accessing a single array element: $ print ${Arr[2]} 3 § Accessing a single array element: $ print ${Arr[*]} 1 2 3 4 foo § Assignment of individual elements: Arr[5]="hi there" 3 Arrays in KornShell (2) § KSH arrays are “sparse” rather than contiguous: Sparse[5]=8 Sparse[15]=12 Sparse[19]=7 § If the indices aren't consecutive, how do we know the array's size? § How do we know the indices for all values? 4
Background image of page 2
1/16/11 3 Arrays in KornShell (3) § Obtain a list of every element in an array: print ${Array[*]} print ${Array[@]} § Getting the size of an array: ${#Array[*]} or ${#Array[@]} § Getting the indices of all array elements: ${!Array[*]} or ${!Array[@]} 5 Reading Into an Array while read -A Data # Splits on whitespace do print Read ${#Data[*]} items. print The third item is ${Data[2]}. done < Some_Data_File § Use the –A option of the read command to split each line read from Some_Data_File into an array § Note: read will still only read one line at a time 6
Background image of page 3

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

View Full DocumentRight Arrow Icon
1/16/11 4 Binary Operators § Recall from ECE264 << n Shift left n bits >> n Shift right n bits Bitwise AND ^ Bitwise EXCLUSIVE OR | Bitwise OR ~ Bitwise negation § Binary operators are considered arithmetic so you must use them within ((…)) 7 Binary Operators (2) integer A=2#1101 integer B=2#0110 integer C (( C = A | B )) print "(( C = $A | $B )) C = $C" (( C = A ^ B )) print "(( C = $A ^ $B )) C = $C” Results (the values actually displayed are in base 10): (( C = 2#1101 | 2#110 )) C = 2#1111 (( C = 2#1101 ^ 2#110 )) C = 2#1011 8
Background image of page 4
1/16/11 5 Scientific Functions § All angles are in radians abs Absolute value acos Arc cosine asin Arc sine atan Arc tangent cos Cosine cosh Hyperbolic cosine exp Exponential with base e int Greatest integer <= to value of expression (floor) log Natural logarithm sin Sine sinh Hyperbolic sine sqrt Square root tan Tangent tanh Hyperbolic tangent 9 Loop Control continue § Used to skip to the next iteration of the inner-most loop. break § Used to end the execution of the inner- most loop. 10
Background image of page 5

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

View Full DocumentRight Arrow Icon
1/16/11 6 Loop Control (2) for i in {0. .4} do if (( i == 1 )); then continue # Skip to i=2 fi print -n " ${i}” done Results in the following output: 0 2 3 4 11 Loop Control (3) I=0 while (( I <= 4 )); do if (( I == 1 )); then break # kill the loop here fi print -n " ${I}" (( I++ )) done Results in the following output: 0 12
Background image of page 6
1/16/11 7 Command Line Arguments § What if we want to loop through the command line arguments? § Easy.
Background image of page 7

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

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

Page1 / 26

Lecture 2 - 1/16/11 ECE364: Software Tools Laboratory...

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