Winter 2018 - January to April 2018 - Updated 2018-03-10 03:49 EST
Do not print this assignment on paper!
- On paper, you will miss updates, corrections, and hints added to the online version.
- On paper, you cannot follow any of the hyperlink URLs that lead you to hints and course notes relevant to answering a question.
- On paper, scrolling text boxes will be cut off and not print properly.
23h59 (11:59pm) Friday March 16, 2018 (end of Week 8)
WARNING: Some inattentive students upload Assignment #7 into the Assignment #6 upload area. Don’t make that mistake! Be exact.
This assignment is based on your weekly Class Notes and covers these topics:
.bash_profile
and .bashrc
PATH
.For full marks, follow these directions exactly:
These tasks must be done in your account via Remote Login to the Course Linux Server.
Do the tasks in order, from top to bottom. Do not skip steps. Most tasks are independent, but some depend on successful completion of a previous task.
READ ALL THE WORDS in each task before you begin the task, especially all the Hints and links.
Verify your own work before running the Checking Program. You won’t have a checking program at your job interview and the Checking Program is not guaranteed to check everything.
Run the Checking Program at the end of the task to grade your work and help you find some of your errors. A perfect mark from the Checking Program does not mean your answers are correct.
When you are done with this Assignment, submit the output of the Checking Program to Blackboard before the due date, following the directions given at the end of this Assignment.
You can use the Checking Program to check your work after you have completed each task.
Most task sections below require you to finish the whole task section before running the Checking Program. You may not always be able to run the Checking Program successfully in the middle of a task or after every single task sub-step. The assignment tells you where you can safely check your work.
You will create file system structure in your CLS home directory containing various directories and files. When you are finished the tasks, leave the files and directories in place on the CLS as part of your deliverables for your instructor to verify.
Assignments may be re-marked at any time on the CLS; you must have your term work available on the CLS right until term end. Do not delete any assignment work until after the term is over!
You can modify your work and check it with the Checking Program as often as you like before you submit your final mark to Blackboard. You can upload your marks to Blackboard as many times as you like before the due date. Partial marks are accepted.
Your instructor will also mark on the due date the work you do in your account on the CLS. Leave all your work on the CLS and do not modify it after you have submitted your final mark to Blackboard.
You must keep a list of command names used each week and write down what each command does, as described in the List of Commands You Should Know. Without that list to remind you what command names to use, you will find future assignments very difficult.
All course notes are available on the Internet and also on the CLS. You can learn about how to read and search these CLS files using the command line on the CLS under the heading Copies of the CST8207 course notes near the bottom of the page Course Linux Server. You also learned how to search the notes in Assignment #05 HTML.
Many students find it extremely helpful to draw a quick graph/picture of their file system directory structure on paper before attempting to answer questions about relative pathnames.
You need to be able to visualize the relative locations of names in the file system tree to answer these questions. Draw the trees on paper!
All references to the Source Directory below are to the CLS directory ~idallen/cst8207/18w/assignment07/
and that name starts with a tilde character ~
followed by a user name with no intervening slash. The leading tilde indicates to the shell that the pathname starts with the HOME directory of the account idallen
(seven letters).
You do not have permission to list the names of all the files in the Source Directory, but you can access any files whose names you already know.
Have you completed all the prerequisites, before attempting these tasks?
Do a Remote Login to the Course Linux Server (CLS) from any existing computer, using the host name appropriate for whether you are on-campus or off-campus. All work in this assignment must be done on the CLS.
Set your PS1
shell prompt, as you did in a previous assignment. This is the last time you will have to do this manually; this assignment configures your .bashrc
file.
Create the assignment07
directory in your usual Assignments
directory.
This assignment07
directory is called the Base Directory for most pathnames in this assignment. Store your files and answers in this Base Directory, not in your HOME directory or anywhere else.
Hints: See your previous assignment for hints on doing the above.
Run the Checking Program to verify your work so far.
You need to understand Start-Up Files and how to use a text editor such as The VI Text Editor to do this task.
.bash_profile
.bashrc
Use a Linux text editor to create your .bash_profile
and .bashrc
files with the minimum suggested content described in Start-Up Files. These files do not exist yet; you must create them.
Do not set any options or aliases in your .bashrc
that you do not understand! If you don’t know the meaning of a setting, don’t use it. You can RTFM in the bash
man page for all BASH settings, and RTFM in command man pages to learn about options to commands.
Using the PS1
variable from Worksheet #2 HTML, set your shell prompt to include at least the basename of your current working directory. (You may also include things such as your user name and/or your computer name.) Also put this variable setting statement in your .bashrc
file.
Your .bash_profile
must contain only one executable line (not counting comment lines). Your .bashrc
must contain at least two executable lines (not including comment lines).
I will be spot-checking your knowledge of your aliases and shell options. Students using aliases they don’t understand will experience much confusion trying to do future assignments. Only use aliases and shell options that you understand.
Answers for assignments, tests, and exams expect default shell behaviour with no custom options set. Don’t get confused!
Verify that nothing prints on your screen after you enter your password when you run the non-interactive shell connection using ssh localhost true
as described in the Start-Up Files section on Non-interactive shells and PS1:
$ ssh localhost true
*** COURSE LINUX SERVER ***
user@localhost's password:
$
For non-interactive commands to work properly, there must be no output on your screen from your start-up files after you enter your password using the above non-interactive command line using the true
command.
Your instructor will mark the .bashrc
and .bash_profile
files in your account after the assignment due date. Do not upload them to Blackboard. Leave them there on the CLS. Do not delete anything from the CLS until after the term is over!
Run the Checking Program to verify your work so far.
You need to understand Shell Variables to do this task.
Follow correct double-quoting procedures when expanding variables, as noted in Shell Variable Quoting.
varenvs.sh
Use the echo
command to display on your screen the value of the environment variable containing your HOME directory.
When you have the right command line, put a copy of the command line into a new file varenvs.sh
in the Base Directory (which should be your current directory). (Put a copy of the command line in the file, not the command output.) You should use a text editor such as The VI Text Editor to create this file.
The file should now contain one command line – exactly the same command line that you typed to display the HOME value above. Look at the contents of the file to make sure it is exactly the same as the command line you used.
If you run the file you created using the shell, it should print just your HOME directory, similar to this:
$ sh -u varenvs.sh
/home/abcd0001
Use the echo
command to display on your screen the value of the environment variable containing your userid.
When you have the right command line, append a copy of the command line to the end of the file varenvs.sh
in the Base Directory. (Append a copy of the command line to the file, not the command output.) You should use a text editor such as The VI Text Editor to edit the file and add the line to the end of this file.
The file should now contain just two command lines. If you run the file using the shell, it should print your HOME directory and your userid.
Use the echo
command to display the value of the environment variable containing your assigned shell.
Append the command you use to do this to file varenvs.sh
in the Base Directory. (Put in the command, not the output.) The file will contain three command lines and should output three lines when you use the shell to run it.
Use the echo
command to display the value of the environment variable containing your shell search path. Append the command you use to do this to file varenvs.sh
in the Base Directory. (Put in the command, not the output.) The file will contain four command lines and should output four lines when run by the shell.
Use the sh
shell to run (execute) your four-line shell script by typing sh -u varenvs.sh
and the values of all four environment variables should display on your screen. (If varenvs.sh
is in some other directory, use the appropriate pathname.)
To verify that you have used proper procedures for expanding variables inside your script, set the HOME
variable to be a GLOB character temporarily and then run the script again like this:
$ HOME='*' sh -u varenvs.sh
Make sure that the first line of script output is the single GLOB character *
and not a list of file names. If you see a list of file names, re-read all the words in the paragraph about double-quoting at the start of this task, above.
Use a text editor such as The VI Text Editor to edit the file and add four or more shell comment lines to the end of the file, describing in your own words the use for or meaning of each of the four environment variables in your script. A shell comment line starts with a number sign (octothorpe, pound-sign, or hashtag) character “#
” and is no longer than 80 characters, e.g.
# This is a shell comment line. It starts with the # character.
# Comment lines should be shorter than 80 characters in this course.
# Comment lines should be added to the bottom (end) of the file.
# You need at least four comment lines in the file, one per variable.
Your instructor will read and verify your comment lines after the due date.
Run the Checking Program to verify your work so far.
PATH
IndexYou must know how to use a text editor and understand how a shell uses a search PATH
variable to do this task. You need to know how to append to a shell variable.
There is a Hints section below that you should read if you have trouble with this task. Always read the task to the end, including all the Hints, before you begin!
wrkpaths.sh
Use a text editor to create a file named wrkpaths.sh
under the Base Directory (which should be your current directory). Put these five command lines into the file:
echo
the current value of your search path environment variable onto your screen, as you did above. (Put the command in the file, not the output.)echo
the new value of the search path environment variable onto your screen again.assignment07check
(the basename of the Checking Program). This line contains a command name and one argument that must be assignment07check
assignment07check
, which it will do using the modified search path that you set earlier in the script. No slashes should appear in this command name, so that the shell uses your modified search path to find it and run it. (Review how the shell search PATH
works.)After you have created your five-line shell script, enable execute permissions on the script file and then run (execute) it using these two command lines:
$ chmod u+x wrkpaths.sh # all lower-case letters
$ ./wrkpaths.sh
Remember how to make a file executable and run it from the current directory; you will need to do this again. Write it down!
When you run the script, each of the five command lines in the script will execute, one after the other. The second line, setting the search path, should produce no output. There will be four outputs that come from the other four lines of the script:
assignment07check
command name, using its own modified search path set on line two.assignment07check
checking program and generate lots of output.Hints:
- You need to know how the shell uses the
PATH
variable to find and run commands.- You need to know how to append to
PATH
.- Remember to quote all variable expansions.
- If you see
command not found
output coming from commands inside the executing script, you have either spelled a command name incorrectly or have not correctly set the shell search path inside the script file. This script will only work if the shell searchPATH
is set correctly near the beginning (top) of the file.- The command that tells you which PATH directory contains a command name is documented in shell search
PATH
and is in your List of Commands You Should Know.
Run the Checking Program to verify your work so far.
You must know how to use a text editor and understand how shells use Quoting to do this task. Remember to read the Hints below.
quotefixer.sh
Copy the script file Badquotes.sh
from the Source Directory into the current directory using the new name quotefixer.sh
as you copy it.
Enable execute permissions on the script file and run the script (as you did in the previous task).
Note that the output of running the script generates an error message at the bottom, and the lines output on the screen don’t match what is written in the script file. For example: many quotes are missing, GLOB characters and variables are expanding, and the spacing of the words is different.
Use a text editor to add Quoting inside the script file so that the text given to echo
on each line is fully quoted to be one single argument to each echo
command, and the text must display on your screen exactly as written in the file, blanks included, with no meta-character expansion by the shell. The correct ten lines of output should look exactly like this when you are finished, including all the extra spaces between some of the words:
Where is the missing question mark after the file name: /etc/passwd?
Is the question mark also missing after the file name: /etc/group?
Do you see any *[square]* *[brackets]* in this line ????????????
The BASH shell prompt is contained in the upper-case variable: $PS1
This line doesn't appear correctly on screen. It's missing the quotes.
This line is also missing "all" the quotes and is not "right" yet.
This line is "also missing quotes". It's output that isn't right yet.
The shell gives an error message on this line; it isn't working.
*** This file is to practice shell quoting. Do you see this line? ***
Do you see this last line with the extra spaces ?
The correct script output, as shown above, is exactly ten lines, 116 words, 687 characters and has a checksum of 59121 1
.
Hints:
You must edit the
quotefixer.sh
file to make the entire line of text on each line one single shell argument toecho
. Review how the shell finds arguments and how to use Quoting to hide all the shell metacharacters, including spaces.You can check whether you have successfully created one single argument on each line by using an alias to temporarily substitute the
argv.sh
program from the Class Notes for theecho
command.You can easily get a copy of the
argv.sh
program from the course notes on the CLS using thenewnotes
symbolic link you created in a previous assignment.Read the comments inside the
quotefixer.sh
file for details on using an alias to runargv.sh
. You have to put theargv.sh
program into the same directory asquotefixer.sh
under the nameargv.sh
and make it executable. See the comments for details.If your line and word count is correct but the number of characters is less, you probably failed to hide spaces to make the entire text one argument to
echo
on each line. You must use Quoting to hide all the blanks and special characters from the shell on each of the lines. Theargv.sh
program will tell you if you got it right.If your output is mostly correct but you can’t find your mistakes, copy and paste the above correct text into a file named
correct
on the CLS and verify its word count and checksum. Then run your script and save (redirect) the script output in fileout
. Then use thediff
command to compare the two files. Thediff
command will show you just the lines where the differences are. In the course notes you can learn about how to use diff.$ sum correct # verify the checksum 59121 1 correct $ ./quotefixer.sh >out # save my script output $ diff correct out # compare correct output with mine [... your output here ...]
quotefixer.txt
When the output of your edited script is correct, run the script and redirect the script output into file quotefixer.txt
in your Base Directory (which should still be your current directory).
The file must contain exactly the same lines, words, and characters as given above. The checksum of the file must be the same as above.
Hint: Make sure you spell the extension on the pathname correctly.
Run the Checking Program to verify your work so far.
That is all the tasks you need to do.
Check your work a final time using the Checking Program below and save the standard output of that program into a file as described below. Submit that file (and only that one file) to Blackboard following the directions below.
Your instructor will also mark the Base Directory in your account on the due date. Leave everything there on the CLS. Do not delete anything.
When you are done, log out of the CLS before you close your laptop or close the PuTTY window, by using the shell exit
command:
$ exit
Nothing seriously bad will happen if you forget to log out, but you may leave behind an empty, “ghost” login session that may take some days to time out and disappear. Always exit
before you close your laptop, PuTTY, or Terminal session.
Summary: Do some tasks, then run the Checking Program to verify your work as you go. You can run the Checking Program as often as you want. When you have the best mark, upload the single file that is the output of the Checking Program to Blackboard.
Since I also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. I do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.
There is a Checking Program named assignment07check
in the Source Directory on the CLS. You can execute this program by typing its (long) pathname into the shell as a command name:
$ ~idallen/cst8207/18w/assignment07/assignment07check
Note the leading tilde ~
character on the command name. You will learn of ways to make this long line shorter in future assignments.
When you are done, execute the above Checking Program as a command line on the CLS. This program will check your work, assign you a mark, and display the output on your screen.
You may run the Checking Program as many times as you wish, allowing you to correct mistakes and get the best mark. Some task sections require you to finish the whole section before running the Checking Program at the end; you may not always be able to run the Checking Program successfully after every single task step.
When you are done with this assignment, and you like the mark displayed on your screen by the Checking Program, you must redirect only the standard output of the Checking Program into the text file assignment07.txt
in your Base Directory on the CLS, like this:
$ ~idallen/cst8207/18w/assignment07/assignment07check >assignment07.txt
assignment07.txt
file name.You can view the output file one-page-at-a-time using the less
program (use the space bar to page forward and use the letter q
to quit):
$ less assignment07.txt
YOUR MARK for
Transfer the above single file assignment07.txt
(containing the output from the Checking Program) from the CLS to your local computer.
YOUR MARK for
Upload the assignment07.txt
file from your local computer to the correct Assignment area on Blackboard (with the exact name) before the due date:
assignment07.txt
file from your local computer. Make sure the assignment file has the correct name on your local computer before you attach it. Attach only your assignment07.txt
file for upload. Do not attach any other file names.assignment07.txt
file on the Upload Assignment page, scroll down to the bottom of the page and use the Submit button to actually upload your attached assignment07.txt
file to Blackboard.Use only Attach File, Browse My Computer on the Upload Assignment page. Do not enter any text into the Write Submission or Comments boxes on Blackboard; I do not read them. Use only the Attach File, Browse My Computer section followed by the Submit button. If you need to comment on any assignment submission, send me EMail.
You can revise and upload the file more than once using the Start New button on the Review Submission History page to open a new Upload Assignment page. I only look at the most recent submission.
You must upload the file with the correct name from your local computer; you cannot correct the name as you upload it to Blackboard.
Verify that Blackboard has received your submission: After using the Submit button, you will see a page titled Review Submission History that will show all your uploaded submissions for this assignment. Each of your submissions is called an Attempt on this page. A drop-down list of all your attempts is available.
assignment07.txt
under the SUBMISSION heading.You will also see the Review Submission History page any time you already have an assignment attempt uploaded and you click on the underlined assignment07 link. You can use the Start New button on this page to re-upload your assignment as many times as you like.
You cannot delete an assignment attempt, but you can always upload a new version. I only mark the latest version.
Your instructor may also mark files in your directory in your CLS account after the due date. Leave everything there on the CLS. Do not delete any assignment work from the CLS until after the term is over!
I do not accept any assignment submissions by EMail. Use only the Blackboard Attach File, Browse My Computer. No word processor documents. Plain Text only.
Use the exact file name given above. Upload only one single file of Linux-format plain text, not HTML, not RTF, not MSWord. No fonts, no word-processing. Linux plain text only.
NO EMAIL, WORD PROCESSOR, PDF, RTF, or HTML DOCUMENTS ACCEPTED.
No marks are awarded for submitting under the wrong assignment number or for using the wrong file name. Use the exact 16-character, lower-case name given above.
WARNING: Some inattentive students don’t Read All The Words. Don’t make that mistake! Be exact.
READ ALL THE WORDS. OH PLEASE, PLEASE, PLEASE READ ALL THE WORDS!