fearless_fool
fearless_fool

Reputation: 35239

Bash not honoring $PATH?

Under OS X 10.8.3, have an environment like this:

$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
Copyright (C) 2007 Free Software Foundation, Inc.
$ echo $PATH
/Users/r/Desktop/Beryl/usr/bin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/bin:/usr/local/bin:/usr/X11R6/bin

There are two copies of irb in $PATH, as properly reported by which:

$ which -a irb
/Users/r/Desktop/Beryl/usr/bin/irb
/usr/bin/irb

But when I run irb I expect to get /Users/r/Desktop/Beryl/usr/bin/irb; instead I get /usr/bin/irb:

$ irb --version
irb 0.9.5(05/04/13)          # this is the wrong version
$ /Users/r/Desktop/Beryl/usr/bin/irb --version
irb 0.9.6(09/06/30)
$ /usr/bin/irb --version
irb 0.9.5(05/04/13)

I don't have any aliases. I should mention that I launched bash by executing this script:

#!/bin/sh
export PATH=/Users/r/Desktop/Beryl/usr/bin:${PATH}
exec /bin/bash

Regardless, why is bash not running the first instance in $PATH?

Upvotes: 3

Views: 389

Answers (2)

anubhava
anubhava

Reputation: 785876

Use following to determine from where irb is being executed:

type irb

To make bash shell to forget all remembered locations use:

hash -r

It appears that bash shell has previous location of irb saved in an internal hash.

Check here fore details about hash in bash: http://linux.about.com/library/cmd/blcmdl1_hash.htm

Upvotes: 4

cdarke
cdarke

Reputation: 44424

It could be the hash that is causing the problem. When you first run a program it reads PATH, but then bash saves the location in an internal hash. It will use this hash subsequently (in the same session), regardless of the value of $PATH.

List existing locations with the hash command.

You can clear the hash with hash -r.

Edit: see also the associative array BASH_CMDS.

Upvotes: 2

Related Questions