Adding things to the
$PATH is not recursive. Only the directories that are present in
$PATH will be searched by your shell when it's looking for executables to run.
To see what's currently on your
$ printenv PATH
4 common tactics when dealing with many directories such as you're facing is to either:
- add them individually, which is perfectly fine,
$PATH can be fairly long.
- use the command
alternatives (man page) to create symbolic links to the various executables in the differing directories. This trades a long
$PATH for having to maintain symbolic links to the various executables.
- create either aliases or wrapper
.sh scripts that can exist in a common directory and will dynamically change the
$PATH or other environment variables as needed.
- Use a tool to manage your environment such as
Where I used to work we used a technology we developed internally called
use scripts which operators would run commands such as
use X, where
X was the name + version of a CAD/CAM software package such as Xilinx. This would automatically add the appropriate directories and environment variables to the user's shell. When they were done with
X they could say
use -no X. to unload this tool from their environment.
More exotic methods
Another approach for building up your
$PATH but in a more modular way would be to mimic the way most systems work by creating a
/etc/profile.d directory. You can make your own, or even utilize your system's
/etc/profile.d directory to facilitate the adding of things to your environment and/or
For example, if you look at your
/etc/bashrc you might notice this construct:
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i" >/dev/null
You could model yourself something similar where you could put fragments of things you want to get added to your
$PATH + environment.
When this loop runs it will incorporate the contents of the various files in your version of the
profile.d directory. You'd just need to create files in your directory with content like this:
You can organize this directory anyway you want.