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? x
has 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? test
containing only the two commands
df
and du
displays nothing (not even an
error message) when executed as “$ test
”.
Why might that happen?
State two ways of making this script behave properly. $ upcase file1 readme README
FILE1 README README
tr
and positional
parameters.] set $(cat foo)
”
generates the error “invalid option
”,
what could be the reason, assuming that foo
is
a short, readable text file? ls -l file
.
Remember the file argument is accessed by using
a positional parameter.
Use the test
command in an if
statement to see if a file exists.]
To extract just a file's modification time from the
ls -l
output, you can set LC_TIME
environment variable to POSIX
; then the
modification time is in the 6th, 7th, and 8th fields of the
output.
You can extract that by resetting the positional
parameters from the output of the ls -l
,
using set
and command substitution.
(There are easier ways but they require knowledge of awk
or other advanced filter commands.)
exit
command 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?
cd2man
containing
these lines:
#!/bin/sh - x=$(find $HOME -name $1 -print) cd $xThe script has correct permissions and
PATH
is 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
man1
exists somewhere in your home directory
tree.
No error messages appeared either.
Why did that happen, and what should you do to make
cd2man
change 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? rm
called
saferm
which uses the interactive mode
only if you use it with more than one filename.
[Hint: use an appropriate if
statement 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
wpollock@YborStudent.hccfl.edu
.
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).