{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 2

# Lecture 2 - ECE364 Software Tools Laboratory Lecture 2...

This preview shows pages 1–9. Sign up to view the full content.

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

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

View Full Document
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
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

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

View Full Document
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" (( 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#100 (( C = 2#1101 | 2#110 )) C = 2#1111 (( C = 2#1101 ^ 2#110 )) C = 2#1011 8
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

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

View Full Document
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
1/16/11 7 Command Line Arguments §੿ What if we want to loop through the command line arguments? §੿ Easy. is an array §੿ A for loop can do this easily: for arg in [email protected] do print \$arg done 13 shift Command §੿ Left shifts the parameters on the command line by n (default n = 1 ) places §੿ The \$0 parameter is NEVER shifted §੿ Often used when §੿ an unknown or non-fixed number of parameters are passed §੿ the parameters are heterogeneous §੿ the number of parameters is large 14

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

View Full Document
1/16/11 8 shift
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 26

Lecture 2 - ECE364 Software Tools Laboratory Lecture 2...

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

View Full Document
Ask a homework question - tutors are online