「哪個」程式需要刷新 Shell 才能查看新安裝的程式?

「哪個」程式需要刷新 Shell 才能查看新安裝的程式?

為什麼 Linux 程式which要求您刷新 shell(例如tcsh在終端機中鍵入)以查看路徑中安裝的新程式?

我很困惑為什麼我無法訪問一個程序,該程序與 中的其他程序具有相同的權限usr/local/binwhich可以清楚地看到。

有人可以用外行人的術語向我解釋這是如何運作的嗎?

答案1

嘗試rehash

man tcsh

   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.

通俗地說:tcsh 希望提供快速回應,因此它建立了一個命令的內部表(大概是哈希表)以及在哪裡可以找到它們。它大概在啟動時執行此操作。不幸的是,它沒有任何機制來通知您或管理員何時執行需要更新該表的操作。

這是我喜歡 ksh 或 bash 而不是 csh 衍生物的眾多原因之一。

答案2

$ 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
$

which使用 Bash 無需刷新 shell,因此與本身無關。一定還有其他變數在起作用。

相關內容