Assignment E

General instructions for all assignments

Provide an answer for each item in each session.
Number each answer with the same number as the corresponding item in the session assignment.
When the answer to the item is a Unix command, show the command and the system's response.
When the system prints more than 5 lines, abbreviate the response to 5 lines (unless more lines are specifically requested), showing the most important parts.
Use vi to create a file for each session, for example, create a file named sessionE1

Session E1

  1. Log into the system.
  2. Use the appropriate command to determine your login shell.
  3. Find your entry in the /etc/passwd file to verify the result of step 2. Put your entry here, in your answer.
  4. Create a Korn subshell.
  5. Use the same command you used above to show that your login shell is still shown.
  6. Use a different command to determine your current shell. It should show that your current shell is the Korn shell.
  7. Create a Bourne Again subshell.
  8. Use the command to show the current shell. It should show that your current shell is the Bourne Again shell.
  9. Exit from your current subshell.
  10. Use a command to determine your current shell. It should show that your current shell is the Korn shell.
  11. Exit from your current subshell.
  12. Use the command to show the current shell. It should show that your current shell is your login shell.
  13. Log out of the system before starting the next session.

Session E2

  1. Log into the system.
  2. Use the who command and redirect the result to a file called file1
  3. Use the more command to see the contents of file1. Put 5 lines from file1 in your answer, including the line containing your login ID.
  4. Create a Korn subshell.
  5. In one command line, use the date and who commands in sequence so that the output of date will display on the screen and the output of who will be redirected to a file called file2. Show the date results and the first two lines from file2
  6. Make a duplicate of file2 and call it file2.bak
  7. Set vi to be your command-line editor.
  8. Use the command-line editor to recall the previously issued date and who commands. Edit the line so that the output of both commands (date and who) are redirected to a file called file3. Use the more command to display the result. Show the date result and the first two who output lines from file3.
  9. Use the command-line editor to recall the original date and who command line which redirects the output of who command to file2
    Edit the line so that the word "date" is misspelled as "bate". Execute the edited command.
  10. Compare the contents of file2 and file2.bak     What do you see?
  11. Using command-line editing, recall the line created with the bate error. Edit it so that the errors also go to file2error     Show the contents of file2error
  12. Exit from the Korn shell and log out of the system before starting the next session.

Session E3

  1. Log into the system.
  2. Create a long listing of your home directory and redirect it to file1   Show the first 5 lines of file1
  3. Edit the previous command so that the output goes to both the screen and file1   You will need to use a pipe and tee to accomplish this. Show the first two lines from the screen and the first two lines from file1
  4. Edit the previous command so that the output goes to both file2 and file3   Show the first two lines from file2 and the first two lines from file3
  5. Set the noclobber option.
  6. Repeat the previous command line from step 4 so that the output goes to both file2 and file3   Do you get any error message? If so, what is it?
  7. Edit the previous command line to force clobbering of the files.
  8. Unset the noclobber.
  9. Repeat the command that caused the error message. Does it work now?
  10. You may log out, or continue with the following session.

Session E4

  1. Log into the system or change to your home directory.
  2. Without using an editor create a one-line file called file1 by using the echo command (use output redirection). This is one of the ways in which we can create a short file quickly.
  3. Check the contents of file1 using the cat command.
  4. Now, without using an editor, create a two-line file called file2 by using the echo command. Use double quotes for the argument of the echo command. Put the opening quote at the beginning of the first line and the closing quotes at the end of the second line. Explain what you just did and why it works.
  5. Check the contents of file2 using the cat command.
  6. In a variable called   statement   store the following data, including the quotation marks:   "UNIX is basically a simple operating system"  
  7. Now use the following command:
    echo "Dennis Ritchie said $statement but you have to be a genius to understand the simplicity."
    What is printed and why?
  8. Now use the following command:
    echo 'Dennis Ritchie said $statement but you have to be a genius to understand the simplicity.'
    What is printed and why?
  9. Now use the following command:
    echo "Dennis Ritchie said \$statement but you have to be a genius to understand the simplicity."
    What is printed and why?
  10. Use an echo command, that uses the variable   statement   and prints the following, including all four of the double quote characters:
    "Dennis Ritchie said "UNIX is basically a simple operating system" but you have to be a genius to understand the simplicity."
  11. You may log out, or continue with the following session.

Session E5

  1. Log into the system or change to your home directory.
  2. Store the word PARENT in a variable called firstVar
  3. Print the value of the variable firstVar (using echo command).
  4. Create a bash subshell.
  5. Store the word SUBSHELL in a variable called secondVar
  6. Print the value of the variable firstVar (using echo command).
  7. Print the value of the variable secondVar (using echo command).
  8. Explain these two results.
  9. Use the exit command to return from the subshell shell back into your login shell.
  10. Print the value of the variable firstVar (using echo command).
  11. Print the value of the variable secondVar (using echo command).
  12. Explain these two results.
  13. You may log out, or continue with the following session.

Session E6

  1. Do NOT change anything in this session; just look at the files.
  2. Log into the system or change to your home directory.
  3. Display the contents of the system startup file (the file name is different in different shells).
  4. Display the permissions for this file. Do you have permissions to change it?
  5. Display the contents of your personal startup file (the file name is different in different shells).
  6. Display the permissions for this file. Do you have permissions to change it?
  7. Display the contents of system-wide shut-down files (if there is one - if none, say none).
  8. If there is one, do you have permissions to change it?
  9. Display the contents of your personal shut-down files (if there is one - if none, say none).
  10. If there is one, do you have permissions to change it?
  11. Log out of the system.

Submission session

Create a heading similar to the heading for assignment A.

Tommy Atkins   replace with your name
CIS 18A    
Winter 2011   replace with the current quarter
Assignment E  replace with the current assignment letter

  1. Use the following command to create a file with your work from the assignment:
    cat headingE sessionE1 sessionE2 sessionE3 sessionE4 sessionE5 sessionE6 > assignmentE.txt
  2. Use e-mail or WinSCP to obtain a copy of assignmentA.txt. Print it using notepad, or otherwise use the Courier New or other mono-space font.
  3. Turn in your printout to the instructor on time.