CSCI 3190 (Directed Study (Unix Power Tools)), Spring 2004:
Homework 4
- Assigned:
- February 27, 2004.
- Due:
- March 8, 2004, at 5pm.
- Credit:
- 10 points.
Read about the following topics,
either by skimming the mentioned online references or in another
book or reference.
- Shell scripts (what they are and how you create them).
Covered in Part 1 (chapters 1 and 2)
of Advanced Bash-Scripting Guide.
- Positional parameters in shell scripts.
Covered in Part 3 (chapter 9)
of Advanced Bash-Scripting Guide.
Also covered in section 3.4
of the GNU Bash Reference Manual.
- Escape characters and quoting (single quotes, double quotes)
in bash.
Covered in Part 2 (chapters 3 and 5)
of Advanced Bash-Scripting Guide.
Also covered in section 3.1
of the GNU Bash Reference Manual.
- Command substitution (using a command in backquotes within
another command) in bash.
Covered in Part 3 (chapter 14)
of Advanced Bash-Scripting Guide.
Also covered in section 3.5
of the GNU Bash Reference Manual.
- Conditionals (if/then/else) in bash:
Covered in Part 2 (chapter 7)
of Advanced Bash-Scripting Guide.
Also covered in section 3.2
of the GNU Bash Reference Manual.
- Loops in bash;
Covered in Part 3 (chapter 10)
of Advanced Bash-Scripting Guide.
Also covered in section 3.2
of the GNU Bash Reference Manual.
- The test command.
Covered in Part 2 (chapter 7)
of Advanced Bash-Scripting Guide.
(For greater portability, it might be best to stick to
the older single-brackets version of this builtin.)
Also covered in section 4.1
of the GNU Bash Reference Manual.
- The bash directory stack (pushd and
popd commands).
Covered in Part 3 (chapter 11)
of Advanced Bash-Scripting Guide.
Also covered in section 6.8
of the GNU Bash Reference Manual.
Do the following programming problems. You will end up with at
one shell-script file per problem. Turn them in by sending mail
to bmassing@cs.trinity.edu, with each of your scripts as an
attachment. If there's any question of which file corresponds to
which problems, explain in the body of the mail message. Please use a
subject line such as ``cs3190 homework 4'' or ``cs3190 hw4''.
You can develop your
scripts on any system that provides the needed functionality, but
I will test them on one of the department's RedHat 9 Linux machines,
so you should probably make sure they work in that environment before
turning them in.
- (5 points)
Do one of the following:
- Write a shell script that renames a file (specified as
a parameter), changing any
blanks in its name to underscores.
If no filename is given, or if the file does not exist,
the script should print an error message.
Hint: See the examples in the February 23 class notes
and the example scripts on the
sample programs page.
- Write a shell script that makes use of a conditional
(if/then/else/fi) and at least one positional
parameter and does something you find useful or interesting.
Include comments at the top of the script describing its
purpose.
- (5 points)
Do one of the following:
- Write a shell script that searches all directories in
your search path for a specified file/executable and prints
the directories where it is found. For example, if the
script is called find-in-path,
find-in-path ls would print /bin or
/bin/ls.
If the specified file is found in more than one directory,
the script should print them all. If it is not found at
all, the script can print an error message or just do
nothing. If no file/executable is specified, the script
should print an error message.
Hint: See the examples in the February 23 class notes
and the example scripts on the
sample programs page.
- Write a shell script that makes use of a loop
(for or while)
and does something you find useful or interesting.
Include comments at the top of the script describing its
purpose.
Berna Massingill
2004-02-27