パスで bash 実行可能ファイルのキャッシュを無効にします。

パスで bash 実行可能ファイルのキャッシュを無効にします。

これはいいえ繰り返します。私が尋ねるのは障害を負うキャッシュを消去する代わりにキャッシュを削除してください。削除が必要なキャッシュがある場合、明らかに無効になっていません。

まれに、私はbashがパスで見つけたものをキャッシュするのを見つけました。それが役に立つからではなく、非常に迷惑だからです。一例:

~ dc$ export PATH=$HOME/bin:$PATH
~ dc$ cat bin/which
#!/bin/bash
echo "my which"
~ dc$ which
my which
~ dc$ rm bin/which
~ dc$ which which
-bash: /Users/dc/bin/which: No such file or directory

別の殻に...

~ dc$ which which
/usr/bin/which

ディスクが遅く、メモリが高価で制限されていて、多くのキャッシュを行うことができなかった昔は、この種のキャッシュが意味があったと確信しています。キャッシュ・パスは、照会コマンドに必要なすべてのディスク・ブロックをキャッシュするよりも安価でした。しかし今日、それは明確な利点を提供せず、解決するよりも多くの問題を引き起こします。これは間違いです。ほぼ間違いです。

無効にする方法さえ見つかりません。どんなアドバイス?

ベストアンサー1

プロンプトを描画する前に、ハッシュされた実行可能ファイルを消去できます。

PROMPT_COMMAND='hash -r'

からhelp hash

hash: hash [-lr] [-p pathname] [-dt] [name ...]
Remember or display program locations.

Determine and remember the full pathname of each command NAME.  If
no arguments are given, information about remembered commands is displayed.

Options:
  -d                forget the remembered location of each NAME
  -l                display in a format that may be reused as input
  -p pathname       use PATHNAME is the full pathname of NAME
  -r                forget all remembered locations
  -t                print the remembered location of each NAME, preceding
            each location with the corresponding NAME if multiple
            NAMEs are given
Arguments:
  NAME              Each NAME is searched for in $PATH and added to the list
            of remembered commands.

Exit Status:
Returns success unless NAME is not found or an invalid option is given.

おすすめ記事