前提:在修改的过程中.bashrc
,经过shopt 在线 bash 手册可以处理的不同 shell 选项的页面shopt
,我遇到了该选项checkhash
,根据描述:
checkhash
If this is set, Bash checks that a command found in the hash table exists
before trying to execute it.
If a hashed command no longer exists, a normal path search is performed.
问题:
- 这个选项有用吗,即它是否提高了 bash 命令的性能?
- 如果是的话,为什么是默认值设置
off
? - 如果,不,为什么这个选项首先存在,是否与旧硬件有关?
答案1
我认为该设置应该改善用户体验,而不是“性能”。
hash -r
当您移动或删除可执行文件时,它应该可以使您不必手动运行。
比较:
bash$ mkdir -p first second; PATH=$PATH:first:second
bash$ echo echo ok > first/ok; chmod 755 first/ok
bash$ ok
ok
bash$ mv first/ok second/ok
bash$ ok
bash: first/ok: No such file or directory
# Yet it's in the PATH!
bash$ hash -r
bash$ ok
ok
相对
bash$ shopt -s checkhash
bash$ mv second/ok first/ok
bash$ ok
ok
bash$ mv first/ok second/ok
bash$ ok
ok
bash$