2

I recently compiled and installed diffutils-3.3 as I needed the --no-dereference switch that is unavailable in the included version of diff. After configure, make, make check, make clean, and install the new version 3.3 of diff was installed in /usr/local/bin.

Running diff --version resulted in the same 3.2 as before installation.

commands and their output follow:

$ which diff
/usr/local/bin/diff

$ whereis -b diff
diff: /usr/bin/diff /usr/bin/X11/diff /usr/local/bin/diff

$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Using full paths, I can confirm that diff version 3.3 is in /usr/local/bin and version 3.2 is in /usr/bin.

Looking at the path, I would expect that since /usr/local/bin appears first, that particular diff should be executed when I call diff without a path. Clearly this is not the case. My question is why and what can I do to obtain the desired result?

Note: Ubuntu 12.04.5

$ uname -a
Linux me-AOD270 3.2.0-80-generic #116-Ubuntu SMP Mon Mar 23 17:11:32 UTC 2015 i686 i686 i386 GNU/Linux
Zanna
  • 70,465
Elder Geek
  • 36,023
  • 25
  • 98
  • 183
  • 1
    About diff being from /usr/bin, see http://askubuntu.com/a/583912/158442. – muru Apr 25 '15 at 02:37
  • 1
    @muru Thanks that explains everything. I actually ended up doing export $PATH$ and trying from a previous terminal which worked. – Elder Geek Apr 25 '15 at 02:45

1 Answers1

1

The root cause of this problem was cached (hashed) entries in the bash lookup table. bash hashes command paths to avoid expensive lookups.

My thanks to @muru for pointing me in the right direction. What I did to resolve the problem was to use the command export $PATH$ which worked for me.

Further research indicates that you can find out if the path is cached (hashed) by using the command type - type diff (in my case) which returns the full path of the command similar to diff is /usr/bin/diff

You can take the surgical approach and remove the cache (hash) for a single command with the command hash -d *command* or in my case hash -d diff which reports success with output of bash: hash: diff: not found

you can also take the less elegant and just as successful approach of dumping the entire cache (hash) table with hash -r which reports nothing.

Sources:

Experience

How get rid of -bash: /usr/{package}: No such file or directory

https://unix.stackexchange.com/questions/5609/how-do-i-clear-bashs-cache-of-paths-to-executables

Elder Geek
  • 36,023
  • 25
  • 98
  • 183