4

Why does the Linux program which require you to refresh the shell (e.g. type tcsh in the terminal) to see new programs installed in your path??

I was baffled why I couldn't access a program, which had the same permissions as other programs in usr/local/bin, which which could clearly see.

Can someone explain how this works to me in layman's terms?

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311

2 Answers2

7

Try rehash

man tcsh says

   rehash  Causes  the internal hash table of the contents of the directo-
           ries in the path variable to be recomputed.  This is needed  if
           new  commands  are  added  to directories in path while you are
           logged in.  This should be necessary only if you  add  commands
           to  one  of  your  own  directories, or if a systems programmer
           changes the contents of one of the  system  directories.   Also
           flushes the cache of home directories built by tilde expansion.

In layman's terms: tcsh wants to provide a snappy response, so it builds an internal table (a hash table presumably) of commands and where they are to be found. It presumably does this at start up. Unfortunately it doesn't have any mechanism to notice when you or an administrator do something that would need that table to be updated.

This is one of many reasons why I prefer ksh or bash to csh derivatives.

0
$ which test
/usr/bin/test
$ ls ~/bin/test
ls: cannot access bin/test: No such file or directory
$ touch ~/bin/test
$ chmod 755 ~/bin/test
$ which test
/home/daniel/bin/test
$

No shell refresh needed using Bash, so it is not related to which in itself. There must be other variables at play.