Add multiple subdirectories under the same parent directory to PATH
Adding a directory to PATH
only makes the executables in this directory available as bare command names. This does not extend to subdirectories.
You can put a loop in your .profile
(not .bashrc
) to add multiple directories, for example:
for d in ~/tools/*/bin; do
PATH="$PATH:$d"
done
(You don't need to repeat export
: when a variable is exported, it stays exported, and modifications are reflected in the environment).
If you create new directories under tools
, this will not be reflected in your ongoing session, only the next time .profile
is read. If this is not satisfactory, you can use a different approach: put a single directory such as ~/bin
in your PATH, and when you install software, create symbolic links in ~/bin
. Stow (or its alternative XStow) is a good way of doing this; see Keeping track of programs for an overview of how this works.