Homework 9, Due Wed Nov 28 @ 1:15pm (3 points)
This is a ten second assignment if you know what you are doing. If this seems
very new to you, it may take as long as 30 minutes. If you do
not get it in that time, arrange to see me before noon on
Wednesday.
- Type, echo $PATH, at the command line. The $ is important,
because as with Perl, it tells the shell that we are referencing a variable
and want its value, not the literal string, PATH. In this case,
PATH is an evironment variable that is set when you launch a new shell,
because the shell program (bash) configures itself by reading a number of
config files including your .bashrc file. Note that the
response from typing, echo $PATH, is a list
(colon separated) of directors on bob. In those directories are found the
command shell commands we use such as ls, cd, etc.
In
fact, any command you type at the shell must be in one of the directories
in this list or the shell will not be able to find and run it. For example,
if you type, dummycommand, the shell will report an error saying
that it cannot find that command. Each "command" is simply a program
that bob knows how to run. It can be a standalone program
compiled down to machine code that runs natively on bobs hardware or it can
be a Perl, Python, Java or some other type of program that is interpreted
in one fashion or another through some intermediary program (i.e. Perl,
Python, or the Java virtual machine).
- Now type, java -version. This command will display the version of
Java that your shell uses by default when you compile or run Java
code. Note that the default version is java 1.4.x. When you type java or
javac at the command line, the shell executes programs by that name.
By default, on bob, those programs work with version 1.4.x of Java. Based
on the discussion above, determine exactly what program is being run by the
shell when you type, java. Send me an email with your answer.
- In order to make our development of a web crawler easier, we will work
with version 1.5 of Java. An easy way to do this is to change our shell
environment so that when we use any Java commands (i.e. java or
javac), the shell knows to use the version 1.5 commands. It turns
out that bob has both 1.4 and 1.5 Java JDK/JREs. In order to make the shell
use the 1.5 JDK when we type java, we need to update our shell
environment variable with the location of the 1.5 JDK binaries. The 1.5
binaries can be found in the directory /opt/jdk1.5.0/bin. Do a
directory listing to see what is in that directory. Note that you find
java, javac, javadoc, and others. Edit your .bashrc file and add a line to
add /opt/jdk1.5.0/bin to your PATH environment variable. Make certain that
you simply add another directory to the PATH variable instead of
completely changing the value of the PATH variable. Three things are
important to note, in order to do this correctly. 1) Multiple directories
are separated by colons in a PATH variable. 2) You can access the current
value of the PATH variable using $PATH. 3) Directories listed first in the
value of PATH will be searched first for commands matching what you type at
the command line. Your changes will not take effect until your .bashrc is
read by the shell. The easiest way to force this is by typing, source
.bashrc at the command line. The first command found that matches a
name is the one that is executed. If you complete this portion of the
assignment correctly, when you type echo $PATH you will see the new
1.5 JDK bin directory in your PATH.
|