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.

I have the terminal editor 'nano' installed in two places on my mac

/usr/bin/nano

/opt/local/bin/nano

The installations are of different versions. The one in /usr does not support my configuration in ~/.nanorc and the one in /opt does.

When I open a file with the command 'nano file', errors are displayed, indicating that the one in /usr was used, however, if I run 'which nano'; the one in /opt shows up.

Isn't `which' meant to search the path for the default? And why wouldn't a call to 'nano' resolve to the same path?

I made a work-around by adding the following line to ~/.profile

alias nano='/opt/local/bin/nano'
share|improve this question
    
The real question is, why do you have two executable files with the same name in directories both of which are in your PATH variable? Remove or rename one of the nano files to nano.bak, and if you still need the binary in both locations, create a symbolic link to the remaining binary. –  Breakthrough Nov 4 '12 at 14:12

1 Answer 1

The binaries are hashed and resolved in the order their parent directories appear in the PATH environment variable. Adjust it according to your needs. This is true for my experiences with bash, at least. Consider looking at the man page for your shell and look for COMMAND EXECUTION and PATH if what I'm telling you does not apply to your shell.

For example, if I wanted foo to mean /home/me/bin/foo and not /usr/local/bin/foo then I would put /home/me/bin/ before /usr/local/bin in the path, where before means left of:

PATH=(...):/home/me/bin:(...):/usr/local/bin:(...)

The path is commonly set up in /etc/profile or in ~/.profile.

share|improve this answer
    
That is my understanding of it too. I am just wondering; why then does 'which' not display the right one? Isn't that utility meant to search PATH in order? –  Eldamir Nov 5 '12 at 7:43
    
It should, and does. Have you tried hash -d nano? Have you looked at hash -l? This seems like one of those cases when one oversees something and thus gets unexpected results. I really don't think which works incorrectly on your system. What could be happening is that nano gets hashed to /usr/bin/nano before the one in opt is found. Apart from that I'm out of advice. –  Ярослав Рахматуллин Nov 5 '12 at 9:55
    
I'll give it a look. Thanks :) –  Eldamir Nov 6 '12 at 7:18

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.