Answer the following questions as briefly (but completely) as possible. (Note the material covered by this homework is from the book and the on-line script resource.) Note that for most of these questions, there is nothing to run or type on a computer. Questions that ask “How should you ...” just require you to think about the answer, not actually try any commands.
PATH=$PATH:$HOME/bin” and “
PS1='$PWD$ '” and you make any changes to the file, how should you activate the changes?
/usr/bin/myscript. How can you prevent any user from executing this script? Should you remove the executable permissions from the script file?
xhas the value
5, and you reassign it with “
x="expr $x + 10"”, what is the new value of
x? What would have been the value if single quotes were used instead? What is the most likely mistake in the above?
testcontaining only the two commands
dudisplays nothing (not even an error message) when executed. Why might that happen? State two ways of making this script behave properly.
$ upcase file1 readme README
FILE1 README README
trand positional parameters.]
set $(cat foo)” generates the error “
invalid option”, what could be the reason, assuming that
foois a short, readable text file?
ls -l file. Remember the file argument is accessed by using a positional parameter. Use the
testcommand in an
ifstatement to see if a file exists.]
To extract just a file's modification time from the
ls -l output, you can set
environment variable to
POSIX; then the
modification time is in the 6th, 7th, and 8th fields of the
You can extract that by resetting the positional
parameters from the output of the
set and command substitution.
(There are easier ways but they require knowledge of
or other advanced filter commands.)
exitcommand terminate the script, when placed in a shell script like this:
( statements; exit )How would you fix this, so the script exits after running the statements?
cd2mancontaining these lines:
#!/bin/sh - x=$(find $HOME -name $1 -print) cd $xThe script has correct permissions and
PATHis set correctly so the script can be found. When you run “
cd2man man1”, you find that the current directory hasn't changed even though the directory
man1exists somewhere in your home directory tree. No error messages appeared either. Why did that happen, and what should you do to make
cd2manchange the current working directory?
foo” and need to have both the output and error messages saved in the single file named “
foo.out”. How should you run the script?
safermwhich uses the interactive mode only if you use it with more than one filename. [Hint: use an appropriate
ifstatement that runs
rm -i "$@"when the number of command line arguments is greater than one. ]
Email your homework assignment, by copy-and-paste (no attachments please!) to . If possible use the “text” and not the “HTML” mode of your email program. Please use the subject similar to “Intro to Unix/Linux Homework Assignment #6 Submission”, so I can tell which emails are submitted homework assignments.
Homework assignments will not be returned.
Please do not send as attachments.
Do not send to
Refer to the Homework and
the Submitting Assignments
sections of your syllabus for more information.
Confused? Send questions about the homework assignment to . Please use a subject similar to “Intro to Unix/Linux Homework Assignment #6 Questions” so I can tell which emails are questions about assignment quiz (and not submissions).