CSC 4630 Meeting 5 January 31, 2007
Next Time Enhance the steps that you used to clean the Moby Dick chapter to create a shell script that takes any chapter as input and produces the ordered lexicon of the chapter with frequency counts of word use. Call the script mobile and save it in your directory CSC4630/scripts
The Future
Setting the Stage What’s the difference between –A programming language and a scripting language –An interpreted language and a compiled language
Setting the Stage (2) What features do you expect a programming language to have? Do these differ if the language is compiled rather than interpreted?
Scripting Languages Variables –Global –Local Control structures –Decision –Looping –Sequence
UNIX Shells Variables –By convention, variables with special meaning are designated in upper case. –User created variables are designated in lower case. –Positional parameters are numbered 1 through 9. Setting and displaying values of variables
Shell Variables Distinguish between the name of the variable and the value of a variable with a particular name. – foo vs. $foo
Shell Variables (2) Special shell variables (global variables) – PATH, the search path – HOME, your login directory – PS1 – PS2 – IFS – MAIL
Shell Variables (3) Some shell variables are denoted by symbols. Traditionally we use the notation for the values of those variables when talking about them. $# -- number of arguments $* -- values of all the arguments $- -- options supplied to shell $? -- return value of previous command $$ -- process-id of shell $! -- process-id of most recent command started with &
Managing Shell Variables Creating dir=`pwd` (Note: the output of any command can be placed in a command line by enclosing the invocation of the command in backquotes.) Showing the value echo $dir
Managing Shell Variables Showing the value of all shell variables set Example today=`date` echo $today echo date echo `date` `date`
Control Structures Looping for i in list do command done while command do command done repeat command until command done Decision if command then command else command fi case value in cases esac
Project 1 Logic –Clear header –Clear trailer –Remove html tags –Remove page designations –Put one word per line –Remove trailing punctuation –Remove leading upper case letters (assuming beginning of sentence words)
Project 1 (2) –Sort words –Create unique list with counts –Sort by frequency
Project 1 (3) Bugs –Numbers –Names –Lost chapter number
Project 1 (4) Bug fixes –Chapter number Roman numeral conversion