------------------------- Week 11 Notes for CST8129 ------------------------- -Ian! D. Allen - idallen@idallen.ca *** Keep up on your readings (Course Outline: average 5 hours/week homework) Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) ------- Review: ------- Chapter 7 - Bourne Shell 7.3.1 - exit status 7.3.2 - semicolon 7.3.3 - && and || 7.3.4 - background use of shell (optional) 7.4 - metacharacters 7.5 - GLOB 7.6 - variables - modifiers - know four basic variable modifiers (p.301) - $1, $2, $* $@ - .8 special vars 7.7 - quoting 7.8 - command substitution - use bash $(...) syntax instead 7.10 - stdio and redirection 7.11 - pipes New: modifiers - know four basic variable modifiers (p.301) ---------- This week: ---------- Readings: Chapter 7 - Bourne Shell 7.9 - shell functions 7.12 - "here" documents Chapter 8 - Bourne Shell Programming 8.1 - intro 8.2 - read 8.3 - arithmetic - use ksh/bash "let" statement instead (12.3.4 p.662) 8.4 - positional parameters (especially $* and $@) 8.5 - conditional constructs and flow control - new: the "case" statement 8.6 - looping - new: the "for" command the "until" command (rare) the "shift" command the "break" command the "continue" command - new: subshells with redirection 8.7 - shell functions 8.8.5 - debugging !! important !! Chapter 15 - Debugging Shell Scripts - ignore the CSH and TCSH scripts - we use the Bourne Shell syntax more than the Bash syntax, since the Bourne syntax works everywhere - 15.2 - very important advice - use the echo and verbose switches! 15.5.1 - 15.3.3 - know your script permissions - 15.3.4 - ignore the book; never put "." in your PATH - 15.3.5 - use a correct #! line - 15.3.6 - Bourne shell scripts do not load aliases - 15.4.1 - always use -u to detect undefined/misspelled variables - 15.4.2 - don't leave off keywords - indent correctly - use "test" and "[" correctly - quote properly - test script arguments (esp. files) before you use them ---------- Next week: ---------- Chapter 8 - Bourne Shell Programming 8.8 - trapping signals Chapter 3 - Regular Expressions and Pattern Matching Chapter 4 - The grep Family: grep, egrep, fgrep Chapter 5 - sed, the Streamlined(sic) Editor RE patterns use some of the same characters as GLOB patterns; but, the meanings are usually different, e.g. *.bak -vs- .*\.bak$ Programs that accept RE patterns may also accept "extended" RE patterns where more metacharacters have meaning. Backslashes in a RE pattern change the meaning of RE metacharacters. If the character had a meaning, it is turned off. If the character did not have a meaning, it is turned on (if it is an extended RE metacharacter), e.g. sed -e 's/\(README\|readme\)\.txt/\1.bak/' When an RE is part of a substitution (s/regexp/text/), metacharacters only have meaning in the RE part of the substitution (the left side). The replacement text is just text and does not need to have any RE metacharacters escaped. However, there are a few additional metacharacters that only have meaning in the replacement text and that need to be escaped to remove that meening.