Mike Fried, Research Professor in Mathematics mfri4@aol.com (or mfried@math.uci.edu or mfried@msubillings.edu) Office: 841 Liberal Arts Building 672-8472 Class logistics: Running Unix on a PC (for math credit), Organization and assessment strategies using Unix for middle and high school math/science (for education credit), Jan 18 -- May 26, 3-5PM, College of Education Room 319. We'll start with Four Topics: 0. Basic Setup: I. Making a file [program] that does something useful with applications: II. Using .cshrc for moving around and editing files: III. Poling files using egrep: I will send by e-mail to those enrolled a file explaining precisely the topics, the testing and the grading. In a day or two after each class you will receive an e-mail summary of each class, referring to some of our class interactions. This will also include the "Problem-of-the-Day" (POD) that will help us focus on the main topics. 0. Basic Setup: We start with the terminal program available to us. command-shift-A gets applications. # Find TextEdit command-shift-U gets utilities. # Find Terminal, command-L to make an alias for it (in File Menu) We need the terminal to execute the file /bin/csh when it starts up # Use Terminal Preferences, try [ls /bin] We'll have two types of commands below, respectively starting Type: and Command: The difference is Type: Means you are typing words intended to go in a file. Command: Means you are typing the words to a command -- in the command line -- and you should follow that by a [return] Sometimes I will use [ ....] to set off a command, or other technical phrase from the rest of a sentence. In a line where these is a #, everything that follows that symbol will be a comment. Later I won't put these beginning explanations of what the line does, but assume we know it from the context. Unix is case sensitive: It matters very much if you type ls or, LS or Ls, or Ls. Start: ls, ls -a, mkdir Win07, cd Win07, echo, echo $cwd. Make a file using echo > temp1 Documentation: man(ual) [command] # Check [man echo] and [man ls]. # Notice this entry: -F Display a slash (`/') immediately after each pathname that is a directory, an asterisk (`*') after each that is executable, an at sign (`@') after each symbolic link, an equals sign (`=') after each socket, a percent sign (`%') after each whiteout, and a ver- tical bar (`|') after each that is a FIFO. # Notice this entry: -a Include directory entries whose names begin with a dot (.). Suggestion: Bring a pendrive formatted for the Mac and copy the file .cshrc (I'll tell you how) and Win07 to it after each class. Then, at the beginning of a new class, copy these back on. I. Making a file [program] that does something useful with applications: Command: echo 'ls $*' > showfiles # $* denotes the collection of arguments you type after the prog_name. # In the command line or in writing programs there is a difference between '...' and "...". # What would happen if I had used echo "ls $*" instead? Command: chmod +x showfiles Command: ./showfiles # For the moment we need the ./ to assure the operating system knows where this program is. Command: ./showfiles # Try showfiles with the following arguments .. [the next folder up], /bin, /usr/bin Command: ./showfiles /usr/bin | more # more is a program and we have [piped] the previous command to it. # Notice we are using programs in /bin already. We will use egrep below from /usr/bin. Command: whereis more # Result is /usr/bin, [whereis whereis] result is /usr/bin/whereis. # This program is supposed to open the file TextEdit. # The ending .app isn't visible -- check apple-A to get the application folder Command: echo "open -a TextEdit.app" > temp1 [return] Command: mv temp1 op-te # The effect is to rename the file # Check [man mv] and [man cp] for m(o)v(e) and c(o)p(y). Command: chmod +x op-te # Turns the file into an executable. Command: ./op-te # The ./ in front won't be necessary later, but right now our .cshrc file isn't set up right. For the future: This gives a way to open an application with a command under the Terminal. But there are many applications and it would be better to have a general approach to opening them. There are also four commonly used editors: TextEdit, Microsoft Word, VI, EMACS VI is preferable for what we are doing because it adds no extra characters. II. Using .cshrc for moving around and editing files: Command: cd Command: cat .cshrc Command: ./op-te .cshrc # We need to have the file produced be Latin-US (Dos) by using the preferences. Type: # lf will display the difference between files and folders Type: alias lf 'ls -F' Type: # The prompt will tell us at any time where we are in the file [folder] system Type: alias cd 'cd \!*;set prompt=`echo $cwd`":""\!="">"; lf' # This is a complex command, calling the previous command. Type: # We can change to the class file at any time by typing win Type: alias win 'cd ~/Win07' Similarly for .login Command: cat .login op-te .login Type: set path=(/bin /usr/bin $HOME \ # \ continues command for two lines -- no spaces after it $HOME/Win07 . ) # [.] indicates the present directory: so op-te instead of ./op-te is sufficient to run op-te For the future: For the first few weeks we will add functionality to the .cshrc file. After you have made a change to .cshrc you must start up a new terminal window to get it to work. You should take a copy of .cshrc home with you by using this command to make a visible copy [cp .cshrc cshrc ] III. Polling files using egrep: Finding out what is in files using various text manipulation programs, with the first egrep being the easiest to use. Command: man egrep We now illustrate using arguments. Type the following into a file named gwcs. # This command takes arguments and checks if they appear in the file .cshrc. words="$*" # Way to the list the arguments to the program for word in $words do echo "See if $word is in .cshrc" check=`egrep "$word" $HOME/.cshrc` # We check if $check is empty, and if not, we see what is the line containing $word if [ "x$check" = "x" ] then echo ".cshrc doesn't contain the word $word. Press return." read return else echo ".cshrc does contain the word $word. Press return to see its line(s)." read return egrep "$word" $HOME/.cshrc fi done Adding functionality: We can expect the .cshrc file to get quite complicated. That calls for adding functionality to the program gwcs. egrep is quite up to that. REFERENCES: 1. Unix Shell Programming, Stephen G. Kochan and Patrick H. Wood, Hayden Books UNIX System Library 2. Mac OSX in a Nutshell, Jason McIntosh, Chuck Toporek and Christ Stone, 2003 Reilly and Associates