On Solaris, can I alias one command to multiple possible locations?

2

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?

Thomas Owens

Posted 2009-11-09T13:51:59.487

Reputation: 3 663

Answers

7

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.

quack quixote

Posted 2009-11-09T13:51:59.487

Reputation: 37 382

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 – 2009-11-09T15:38:11.530