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.

Let's say I have a script called bob. It might be in two locations: /usr/local/bin/bob or /usr/local/bin/scripts/bob. Is there a way I can alias bob to both locations and it will stop whenever it finds bob? So if bob is in /usr/local/bin/bob, it will stop there, otherwise it will look in /usr/local/bin/scripts/bob?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

This is what your PATH environment variable is for.

Arrange your PATH environment variable so that both locations are on the path, AND in the order you want them to to be checked.

So in your example, /usr/local/bin should be earlier in the PATH than /usr/local/bin/scripts.

Most systems will probably have /usr/local/bin already in the system path, so you'll only need to add the second location to your shell startup scripts. If you're using bash, this command would do:

export PATH=$PATH:/usr/local/bin/scripts

Other shells will vary.

share|improve this answer
1  
+1: Exactly what I came in here to say. Bin directories are a good place to store commands anyway; rather than putting your script directory in the path, you might want to put links to your script commands in the bin directory...But that's a personal preference. –  Satanicpuppy Nov 9 '09 at 15:38

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.