
Linux プログラムでは、パスにインストールされた新しいプログラムを確認するためにwhich
、シェルを更新する (たとえば、tcsh
ターミナルに入力する) 必要があるのはなぜですか?
明らかにusr/local/bin
他のプログラムと同じ権限を持つプログラムにアクセスできないのはなぜなのか、私は困惑しました。which
誰かこれがどのように機能するかを一般の人にもわかるように説明してくれませんか?
答え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 は素早い応答を提供したいので、コマンドとその場所の内部テーブル (おそらくハッシュ テーブル) を作成します。これはおそらく起動時に行われます。残念ながら、ユーザーまたは管理者がそのテーブルの更新を必要とする操作を行ったときにそれを通知するメカニズムはありません。
これは、私が csh 派生言語よりも ksh や bash を好む多くの理由の 1 つです。
答え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
$
Bash を使用する場合、シェルの更新は必要ないので、それ自体には関係ありませんwhich
。他の変数が影響しているはずです。