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.

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?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
1  
Does one have to do this every time a new program is installed through e.g. the package manager as well? –  Daniel Andersson Apr 13 '12 at 15:55
2  
@DanielAndersson: Almost certainly, if you use tcsh. –  RedGrittyBrick Apr 13 '12 at 15:58
    
*shivers* :-) –  Daniel Andersson Apr 13 '12 at 16:06
    
I typically use Bash, so maybe that's why I'd never noticed this before... apparently tcsh was my default shell for the stock terminal shortcut in CentOS 6.2... (or at least the version I had). :) –  Jason R. Mick Apr 13 '12 at 17:20
add comment
$ 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.

share|improve this answer
    
Apparently tcsh works differently (see above)... –  Jason R. Mick Apr 13 '12 at 17:21
add comment

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.