Legible PATH and CLASSPATH
January 24, 2007 Ted Holt
One of the things I don’t like about the Integrated File System (IFS) is its directory-based structure of untyped files. I consider the library system of strongly typed objects a much more robust architecture. Nevertheless, the IFS is reality and I have to deal with it. Here’s a short and simple tip for reading those ugly, almost indecipherable PATH and CLASSPATH variables we have to put up with.
The PATH and CLASSPATH variables contain lists of directories, separated with colon characters. They function like library lists, in that the system searches the lists when looking for certain things. The PATH variable lists the directories that are to be searched when looking for files. The CLASSPATH variable lists the directories that are to be searched for Java classes. The longer these variables get, the uglier they get. Here’s an example of a relatively benign CLASSPATH.
A simple Qshell command gives CLASSPATH an air of civilization.
echo $CLASSPATH | tr ":" "n"
Here’s the result:
. /Aps /java/msbase.jar /java/msutil.jar /java/mssqlserver.jar /qibm/ProdData/HTTP/Public/jt400/lib/jt400.jar
So how does it work? The echo command writes the CLASSPATH value to standard output. The pipe (vertical bar) picks up echo’s output and passes it along to the tr (translate) utility, which converts colons to line-feed characters. The output goes to standard output, which in this case is a green-screen Qshell session.
Want to make it even clearer? Number the lines!
echo $CLASSPATH | tr ":" "n" | cat -n
Here’s the numbered list:
1 . 2 /Aps 3 /java/msbase.jar 4 /java/msutil.jar 5 /java/mssqlserver.jar 6 /qibm/ProdData/HTTP/Public/jt400/lib/jt400.jar
The second pipe feeds the output of tr to the cat utility, which displays the lines. The n switch tells cat to number the lines as it displays them.