PATH question (newbie)
Rob Park
rbpark at gmail.com
Mon Apr 18 01:47:03 UTC 2005
On 4/17/05, Matthew S-H <mathbymath at aol.com> wrote:
> How do I change my PATH to include everything in /opt/ ?
Ok, the other guys are freaking out telling you this is a bad idea,
but I think I understand your question more than they do.
Back in the days when I used to run LFS[0], I'd install programs into
/opt/programname instead of the default /usr/local that most packages
like to install to. Effectively, /opt became something like the
equivalent of Windows' C:\Program Files directory. Each program has
it's own subdirectory there. I assume that this is what you are doing.
And now you want the programs you've installed to be in your path.
This is not a problem. What you want to do is something like this:
PATH=$PATH:$(echo /opt/*/bin|sed -e 's/ /:/g')
So lets say you've got 3 programs installed into /opt: "foo", "bar",
and "test". Each of these programs keeps it's binaries in "bin"
directory below their own directory. This means you need to add
/opt/foo/bin, /opt/bar/bin, and /opt/test/bin to your path in order to
run those programs. The above snippet is very simple, The first thing
it does is expands /opt/*/bin (which is to say, it finds all the
directories in /opt that contain a subdirectory called "bin", and then
prints that out:
$ echo /opt/*/bin
/opt/bar/bin /opt/foo/bin /opt/test/bin
Then we need to change the spaces into colons (":"), because that's
how the $PATH variable separates each directory in the path:
$ echo /opt/*/bin|sed -e 's/ /:/g'
/opt/bar/bin:/opt/foo/bin:/opt/test/bin
Then we need to add this on to the end of the current $PATH variable:
$ echo $PATH:$(echo /opt/*/bin|sed -e 's/ /:/g')
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/opt/bar/bin:/opt/foo/bin:/opt/test/bin
And then finally we assign the resulting value back into the $PATH variable:
PATH=$PATH:$(echo /opt/*/bin|sed -e 's/ /:/g')
You'll want to save that in your ~/.bashrc so that it gets set each
time you log in, so you don't have to keep writing it.
--
Urban Artography
http://artography.ath.cx
More information about the ubuntu-users
mailing list