these are all using csh... you don't need to know both bourne shell and c shell... just make sure you know one well enough to be able to do stuff like this. 1. grep "^From " $MAIL > ~/.newmail echo "new emails:" if (-e ~/.oldmail) then comm -13 ~/.oldmail ~/.newmail else cat ~/.newmail endif mv ~/.newmail ~/.oldmail 2. filter: tr A-Z a-z | tr -s ' ' | sed 's/^ *\(.*\) *$/\1/' | sed 's/^ *$//' | awk -f shrinkblanks.awk shrinkblanks.awk: BEGIN { blank = 0; foundfirstnonblank = 0 } /^$/ { blank = 1 } /./ { if (blank == 1 && foundfirstnonblank == 1) print "" print blank = 0 foundfirstnonblank = 1 } the first tr does the lowercase, second tr turns consecutive space into one space, first sed removes leading and/or trailing spaces, second sed turns lines containing only whitespace into blank lines, awk removes leading and trailing blank lines, and turns consecutive blank lines into one. 3a. foreach song (*.mp3) echo currently playing $song:r if(-e $song:r.txt) then cat $song:r.txt endif mpg123 $song >& /dev/null end 3b.this one's pretty hard... i wrote a shell script called shuffle that looks like this: awk 'BEGIN { srand() }{ print rand() " " $0 }' $1 |sort -n|sed 's/^.* //' it uses awk to add random numbers to the beginning of each line, sorts the file [with the random numbers at the front of each line], then removes the random numbers. instead of putting '*.mp3' in the foreach loop, we use `ls *.mp3 | shuffle` 4a.if you don't put the curly braces there, the shell will think you're trying to use a modifier on the PATH variable [like $song:r in question 3a]. 4b.i know of two possiblities: addpath isn't in his path, or /bin/csh doesn't exist on his system. note that if he didn't set execute permission, he would have received a "permission denied" error. 4c.shell scripts are not executed in the current shell, they're executed in subshells. remember that environment variables are visible to the current shell and all subshells. this means that shells scripts can't modify environment variables in the "parent" shell. any changes to environment variables will disappear when the shell script is finished running. 4d.instead of saying "addpath /usr/bin", you can say "source addpath /usr/bin". source means run the shell script in the current shell. another workaround is to make addpath an alias, instead of a shell script: alias addpath setenv PATH '${PATH}':\!:1 note that we need to use the single quotes around ${PATH} to keep the shell from expanding the variable reference when we type in the alias =] 5. first, i made a sed script called 'evens.sed' that contains the following two commands: n p to get the even numbered lines [assuming line numbers start from 1], i would say: cat | sed -n -f evens.sed and to get the odd numbered lines, i would say: cat | tail +2 | sed -n -f evens.sed note that the 'n' in sed will print the current line if the '-n' option isn't specified [check the sed manpage]. so, if you try to be sneaky [i tried to be sneaky] and try to use "sed -e n", it'll print all the lines of the file. 6. a.out | grep '\*\*\*' note that we had to quote the hell out of this thing. why? suppose we tried to grep ***. the shell would expand *** to the names of all the files in the current directory. this is bad. to fix this, we use "***". the next problem is that an asterisk has special meaning to grep [it matches 0 or more occurrences of the previous expression, remember?]. so, to actually match asterisks, we need to put backslashes in front of them. 7. scp cs186-ay@www-inst.eecs:~cs186/public_html/midterm_solution.pdf . this trick actually comes in handy quite often, since the webserver is frequently overloaded.