Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to recursively add a directory to my $PATH variable? Let's say I have a directory structure like the following:

/usr/local/bin
    - /nodejs-x.x
    - /redis-x.x
    - /mongodb-x-x

Can I add /usr/local/bin to the $PATH and allow it to recursively cover the subdirectories?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Not directly, no. Entries in $PATH are not recursive.

What you can do is:

for d in /usr/local/bin/*/; do
    PATH+=":$d"
done

Another option is to put symlinks in /usr/local/bin:

cd /usr/local/bin
ln -s myapp-1.2/myapp myapp
share|improve this answer
    
Alright, makes sense. Is there any reasonable limit on the length of the $PATH variable? I guess it can be as long as you want but is there some drawback to having it super long? –  ajackbot Oct 11 '11 at 13:06
    
@jackweeden: The environment block is limited to 1/4 of the allowed stack space (as shown by ulimit -a; 2 MB by default), and separate strings (key=value pairs) are limited to 32 memory pages (32 kB on a 4-kB-pages architecture). –  grawity Oct 11 '11 at 13:32
    
@jackweeden: A minor drawback is that all directories will have to be checked, one by one, for every command you run. Even though bash remembers the results after first use, it doesn't share this information among instances and forgets after exiting. With modern storage media this isn't much of an issue, though. –  grawity Oct 11 '11 at 13:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.