It looks like when adding a directory into $PATH, its subdirectories are not added recursively. So can I do that? Or is there a reason why this is not supported?
Add them recursively using find like so:
PATH=$PATH$( find $HOME/scripts/ -type d -printf ":%p" )
WARNING: As mentioned in the comments to the question this isn't encouraged as it poses a security risk because there is no guarantee that executable files in the directories added aren't malicious.
The usual unix directory structure has application files sorted into directories by kind:
bin for executables,
lib for libraries,
doc for documentation and so on. That's when they are installed in separate directories; often applications are grouped into a few directories (hence many systems have just three directories in
/bin). It is rare to have both executable files and subdirectories inside a directory, so there's no demand for including a directory's subdirectories in
What might occasionally be useful is to include all the
bin subdirectories of subdirectories of a given directory in
for d in /opt/*/bin; do PATH="$PATH:$d"; done
However, this is rarely done. The usual method when executables in non-standard directories are to be in
$PATH is to make symbolic links in a directory in the path such as
stow utility (or
xstow) can be useful in that regard.
One reason that this is not supported is because the bin/ (and similar) directories use symbolic links to point to the specific directories where actual executables for programs are installed.
So, if your
/usr/local/bin (which it most likely does) that folder is full of symbolic links (like
ruby) which point to the specific directory where the code to run ruby is found (like
This is why you don't have to specify each executable's folder in your
$PATH; the symbolic links customarily found in bin/ type directories handle that for you.