0

I come from using cygwin on Windows, and I just started using a mac. I'm wondering why it seems that search paths don't work like they should.

If I have a program in /usr/bin/prog and I delete it. It seems to keep trying that exact path instead of searching for it again (let's say I move it to /usr/local/bin).

Is this due to the terminal app or is it something specific to mac? Also, if I want to install a new version of python into /usr/local/bin, is the right way to do it to remove it from /usr/bin/?

vonhogen
  • 2,459

4 Answers4

3

You don't say which shell you're using, though your question is tagged with bash. The default Mac OS X shell is tcsh, which If you're using tcsh or csh, they cache a table of items on your path. In order to refresh the table, issue the rehash command at the shell prompt.

You'll need to do this whenever you move or delete an executable, or if you add something to your path.

If you're really using the bash shell then this doesn't apply.

Eric
  • 384
2

OS X terminal will try the paths declared in your PATH variable, in order, until it finds it or runs out of places to check. You can check what your PATH variable is by typing the following at the command prompt:

echo $PATH

You can run the following from the command prompt to view where your shell is finding the program in question:

which prog

If you want to upgrade python, I recommend installing it to the same location as it already exists. If you want to have more than one version installed to your machine at a time, then installing it in /usr/local/bin would be a logical choice IMO.

0

From what I understand when you execute a program it will search the folders on your $PATH variable, which is separated by ":" eg.

/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin

Is your $PATH set up correctly? To find this out use:

echo $PATH

You can also use which python to find which version and from where it is running. I believe this is also a left to right search so it will take the first program named python it finds on the path.

Jim
  • 101
0

Instead of using

which prog

you may use the Bash builtin

type -P prog

# some examples using: type -P cmd
$(type -P prog) arg1 arg2 arg3 ...
myls=$(type -P ls) && $myls -l

For more information see

help type

# The -P flag forces a PATH search for each NAME, even if it is an alias,
# builtin, or function, and returns the name of the disk file that would
# be executed.

Yet another option might be to try

help command
command -p prog

HTH