.. $Id: index.rst 87 2007-10-11 22:46:18Z selfpace $ ====================== CS 9E - Assignment 1.2 ====================== -------------------------- The Shell & Simple Filters -------------------------- .. :Last Updated: $Date: 2007-10-11 15:46:18 -0700 (Thu, 11 Oct 2007) $ Background ========== Overview -------- This assignment will give you an overview of the UNIX shell. The shell is your basic means of interaction with the system. Because you are using a cs9e account, we have customized your shell for use in this course. Shell accounts that you have on other systems and for other classes will more than likely look slightly different, but they all behave similarly. This assignment will teach you how to use the shell and how to customize it for your own needs. Reading ------- Das: Ch. 7, 9 (excluding 9.10), 10, 11.2 Assignment ========== Use 'script' (Section 2.8) to record your session, so you can show it to a tutor. Part 1 - Metacharacters And Quoting ----------------------------------- Perform the following operations, and be prepared to explain the commands you used to a tutor in addition to recording them in your transcript. 1) From within your home directory, perform a ls operation shows all *directories* that begin with a ".". You should not see plain files, and you should not see the contents of these directories. Example:: ~ $ ls _____________ ../ ./ .ssh/ .ssh2/ .sunw/ .tin/ 2) Use quoting or escaping where necessary (and only where necessary) to properly create directories with the following names: a) !*\ b) $HOME c) ... d) "What's For Dinner?" e) ``-`` I.e., if you do an "ls", you should see:: $ ls -a !* - . .. ... $HOME "What's For Dinner?" 3) List all files in /usr/bin which begin with the letter a, b, or c. 4) Echo every 2 letter combination of a, b, c, and d including doubles. I.e.:: $ echo __________ aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd Hint: Curly braces can be nested. Part 2 - Environment Customization ---------------------------------- Make the necessary changes to your shell configuration files to do the following. You will need to show the results as well as the changes to your tutor for checkoff. After being checked off, feel free to undo these changes. 1) Change your prompt. 2) Create a ~/.todo which is displayed whenever you login remotely but not when you open a terminal in X. 3) Create a directory "bin/" in your home directory, and add this directory to your shell's path. Once you've done this, any executable in "bin/" can be run by invoking its name on the shell, rather than giving the full path to the executable. What is the order in which the path is searched? Can you foresee problems if a rogue creates a malicious executable "ls" in "bin/"? 4) Add a command alias to your shell. For example, you may want create an alias that automatically adds an option to a command. E.g. if you use emacs as editor, one convenient alias suppresses emacs starting an X11 window. You can achieve this by running emacs with the -nw option. Part 3 - Piping and Redirection ------------------------------- The file `al.batters.88`_ contains the Final Official 1988 American League batter statistics. The "position" category lists positions at which the player played 20 or more games. Each line of the file contains the following information about a player, organized into fields separated by one or more blanks: .. _`al.batters.88`: al.batters.88 1) his name 2) his team 3) his position or positions 4) whether he bats right-handed or left-handed 5) his batting average (hits divided by at-bats) 6) the number of games he played 7) how many "at bats" he had 8) how many runs he scored 9) how many hits he had 10) how many total bases he had (1 for each single, 2 for each double, etc. 11) how many doubles 12) how many triples 13) how many home runs 14) how many runs batted in 15) how many sacrifice hits 16) how many sacrifice flies 17) how many times he was hit by a pitch 18) how many walks 19) how many intentional walks 20) how many times he struck out 21) how many stolen bases 22) how many times he was caught stealing 23) how many double-plays he hit into 24) his on-base-average Use piping and UNIX commands you have learned about to answer the following questions. Be prepared to explain the commands you used to a tutor in addition to recording them in your transcript. 1) Devise a single pipeline (a command constructed entirely of one or more pipes) that prints the names and batting averages of the ten players whose batting averages are the highest. (Hint: Our solution uses tr, sort, cut, and head) 2) Devise a single pipeline that prints the name of the batter who played the most games of all batters who hit no home runs along with the number of games he played. (Hint: Our solution uses tr, cut, sort, and head) 3) Devise a pair of commands, neither containting any semicolons, that prints the names of batters that were in both the top ten in batting average and home runs. The first command will generate a file containing the names of the players with the top ten batting averages; the next command will compare these names with the top ten home run hitters. (Hint: Our solution uses tr, sort, cut, head, and comm. Important: make sure that hitters with the same number of home runs are arranged in order by batting average.) You may assume that there is at least one AL player who hit no home runs in 1988, that at least one player ranked in the top ten in batting average and in the top ten in number of home runs, and that at most one player with a given number of home runs also has one of the top ten batting averages. Note the difference between sorting twice and sorting on two keys. Your pipeline will run more efficiently if head appears as early in the pipeline as possible. (Why?) Assignment Checklist ==================== Part 1 ------ * Student has correct answers for all questions and can intelligently explain how they reached those answers. * Student can adequately explain how quoting works in the shell. * Student can adequately explain how ``*``, ``[]``, and ``{}`` wildcard matching works in the shell. Part 2 ------ * Student has changed their shell prompt by properly modifying their shell configuration files. * Student's ~/.todo file is shown when they login. * Student's finger information is set correctly. Part 3 ------ * Student shows script containing the required commands. * Student can intelligently describe how piping works and demonstrate their understanding of standard input and output.