======================= CST8129 Lab Exercise #3 (Week 5) ======================= -IAN! idallen@ncf.ca EDIT: replace this line with your full Assignment Submission Label Due: 23:00 (11pm) Friday September 27, 2002 Marks: 4% Purpose: - review some of the work done so far (Chapter 1 and Chapter 8) Hand in format: online submission only - no paper, no diskettes Instructions (4 Instructions): 1. Copy this entire exercise file to your account. 2. Edit the file to add your answers in all the places indicated. Many answers should be edited in place of a line marked "EDIT:". The first "EDIT:" line is near the top of this file. 3. Change the permissions on this answer file to "read-only" for you, "read-only" permissions for group, no permissions for other people. 4. In the Linux lab, copy your answer file to this location: ~alleni/cst8129/02f/lab03exercise/xxxxnnnn.txt where xxxxnnnn is your Algonquin userid (e.g. abcd0001). Files with the wrong name or wrong Unix permissions will be penalized. Your exercise is due online before the date and time given above. Late penalty for this assignment: 33% per day ############################################################################ Part 1: Using VI, cut and paste the six lines marked "REORDER" below to put them in the proper order of shell processing. Warning: You must cut and paste the *exact* lines given below, without modification. Any errors in spelling or typing will reduce your mark. REORDER: shell expands $-variables REORDER: shell expands pathname globs (wildcards, e.g. *) REORDER: shell looks for the command name in $PATH and runs it REORDER: shell identifies and removes I/O redirection REORDER: shell splits the command line into words (tokens) REORDER: shell again word-splits unquoted $-variable expansions Do not modify the lines - rearrange them only. ######################################################################## In the following parts, use VI to remove *only* the "EDIT:" place-holder lines and replace each one with the correct output. Where the file says "mkdir empty ; cd empty", the intent is to create an empty directory - make sure you do the exercise starting in an *empty* directory. (Remove everything in the directory; or, make a new, empty one.) WARNING: If you use "rm *" in the wrong directory, you will delete all your files, with no recovery possible. Be careful to work in an empty sub-directory for these exercises! Pay attention to the different types of quotes in this file: Double quotes: "" Single quotes: '' Back quotes: `` Do not edit or replace anything below except the "EDIT:" lines. ######################################################################## Part 2: $ mkdir empty $ cd empty $ touch aa ab ac ad ae af $ x='a* b* c* d*' $ echo $x EDIT: replace this line with the correct output $ echo "$x" EDIT: replace this line with the correct output $ echo '$x' EDIT: replace this line with the correct output Part 3: $ mkdir empty $ cd empty $ ls -a EDIT: replace this line with the correct output $ x="foo*" $ echo $x EDIT: replace this line with the correct output $ echo "$x" EDIT: replace this line with the correct output $ echo '$x' EDIT: replace this line with the correct output $ touch foobar $ ls EDIT: replace this line with the correct output $ echo $x EDIT: replace this line with the correct output $ echo "$x" EDIT: replace this line with the correct output $ echo '$x' EDIT: replace this line with the correct output $ echo hi >$x $ ls EDIT: replace this line with the correct output $ echo there >"$x" $ ls EDIT: replace this line with the correct output $ echo mom >'$x' $ ls EDIT: replace this line with the correct output $ rm $x $ ls EDIT: replace this line with the correct output Part 4: $ mkdir empty $ cd empty $ x='a b c d' $ touch $x $ ls | wc EDIT: replace this line with the correct output $ rm * $ touch "$x" $ ls | wc EDIT: replace this line with the correct output $ rm * $ touch '$x' $ ls | wc EDIT: replace this line with the correct output Part 5: $ mkdir empty $ cd empty $ x='a b >out' $ echo $x EDIT: replace this line with the correct output $ touch 'a b >out' $ ls EDIT: replace this line with the correct output $ echo * EDIT: replace this line with the correct output Part 6: $ foo='bar haven' $ echo foo $foo "$foo" '$foo' bar EDIT: replace this line with the correct output $ alias foo='echo hi ; echo "a b"' $ foo bar EDIT: replace this line with the correct output $ echo a ; echo b EDIT: replace this line with the correct output $ x=';' $ echo a $x echo b EDIT: replace this line with the correct output Part 7: $ mkdir empty $ cd empty $ ls /bin >out $ cat out $ wc out EDIT: replace this line with the correct output $ ls /bin >out $ sort out >out $ wc out EDIT: replace this line with the correct output $ ls /bin >out $ head out >out $ wc out EDIT: replace this line with the correct output $ ls /bin >out $ tail out >out $ wc out EDIT: replace this line with the correct output $ ls /bin >out $ tr 'a-z' 'A-Z' out $ wc out EDIT: replace this line with the correct output $ ls /bin >out $ diff out out >out $ wc out EDIT: replace this line with the correct output $ ls /bin >out $ wc out >out $ wc out EDIT: replace this line with the correct output Part 8: Note: The four-word line shown below after the "read" command is what you should type in on your keyboard, in response to the "read": $ read a b one two three four $ echo "$a" EDIT: replace this line with the correct output $ echo "$b" EDIT: replace this line with the correct output Part 9: $ mkdir empty $ cd empty $ touch abc aa ab ac ad ae af 'a?' $ rm a? $ ls EDIT: replace this line with the correct output $ touch abc aa ab ac ad ae af 'a?' $ rm a\? $ ls EDIT: replace this line with the correct output $ touch abc aa ab ac ad ae af 'a?' $ rm 'a?' $ ls EDIT: replace this line with the correct output $ touch abc aa ab ac ad ae af 'a?' $ rm ''a?'' $ ls EDIT: replace this line with the correct output $ touch abc aa ab ac ad ae af 'a?' $ rm "a?" $ ls EDIT: replace this line with the correct output $ touch abc aa ab ac ad ae af 'a?' $ rm ""a?"" $ ls EDIT: replace this line with the correct output $ touch abc aa ab ac ad ae af 'a?' $ rm a?? $ ls EDIT: replace this line with the correct output Part 10: $ mkdir empty $ cd empty $ touch .aa .ab '.a?' '.a*' abc .abc .abcdef .xylophone $ echo ??? EDIT: replace this line with the correct output $ echo .?? EDIT: replace this line with the correct output $ echo .??* EDIT: replace this line with the correct output $ echo .a? EDIT: replace this line with the correct output $ echo .a* EDIT: replace this line with the correct output $ echo .* EDIT: replace this line with the correct output Part 11: $ mkdir empty $ cd empty $ touch a ab abc abcd abcde abcdef 1 12 123 1234 12345 123456 $ echo ? EDIT: replace this line with the correct output $ echo ?? EDIT: replace this line with the correct output $ echo ??? EDIT: replace this line with the correct output $ echo *c* EDIT: replace this line with the correct output $ echo *[d4]* EDIT: replace this line with the correct output $ echo [0-9][0-9] EDIT: replace this line with the correct output $ echo [a-z][a-z][a-z] EDIT: replace this line with the correct output $ echo [!a-z]* EDIT: replace this line with the correct output $ echo [!0-9]* EDIT: replace this line with the correct output $ echo *nosuch* EDIT: replace this line with the correct output $ echo [a-z][0-9] EDIT: replace this line with the correct output $ echo [b-z]* EDIT: replace this line with the correct output Part 12: $ echo hi >out $ cat out EDIT: replace this line with the correct output $ echo do you see this | cat EDIT: replace this line with the correct output $ echo do you see this | cat out EDIT: replace this line with the correct output $ echo hi | wc EDIT: replace this line with the correct output $ echo hi >out | wc EDIT: replace this line with the correct output $ cp out out2 | wc EDIT: replace this line with the correct output $ echo "on standard output" | wc EDIT: replace this line with the correct output $ echo 1>&2 "on standard error" | wc EDIT: replace this line with the correct output $ ls -ldi ~alleni/cst8129/02f/foo.txt nosuchfile 1>out 2>errors $ cat out EDIT: replace this line with the correct output $ cat errors EDIT: replace this line with the correct output ######################################################################## End of exercise. If you don't understand any of the above output, re-read Chapter 8 and then contact your instructor with questions. Questions regarding course content can be posted to the course discussion news group, available under the News&Discussion button.