---

Linux Journal: Shell Functions and Path Variables, Part 3

“In this final article in the series, I’ll describe the
remaining path handling functions and point out a few
implementation issues. Before I do that, however, I will describe a
utility called makepath. This reads either standard input or its
argument list, builds a colon-separated path variable (pathvar)
from those lines read and echoes it to standard output. For
example:

$ makepath /bin /usr/bin /opt/kde/bin
/bin:/usr/bin:/opt/kde/bin

“First, let’s look at listpath, which echoes the pathels making up
a pathvar on separate lines, as in:

$ listpath -p MANPATH
/usr/man
/usr/local/man
/opt/CC/man

“Using listpath has two advantages over merely echoing $MANPATH.
First, it’s much easier to read the pathels when they appear on
separate lines; and secondly, you can pipe its output through
grep…”

“UNIX can present a bewildering array of tools and
techniques, and it’s almost impossible for any individual to be
intimately familiar with all of them. In my experience, the best
developers carry around a large bag of simple but useful techniques
and are able to combine them rapidly into a working solution.

You don’t need to know every detail of every tool to do useful
work, but you do need a bag of tricks you understand.”

Complete
Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis