0

Premise: In the process of modifying .bashrc, and going through the bash manual for shopt online page for the different shell options that can be handled by shopt, I came across the option checkhash, which according to the description:

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.

Questions:

  1. Is this option useful, i.e, does it increase the performance of the bash commands?
  2. If, yes, why is the default value set to off?
  3. If, no, why does the option exist in the first place, is it something to do with older hardware?
2
  • Adding more tests before a command is run won't improve performance superuser.com/questions/733744/… – guest Feb 21 '20 at 6:24
  • Thanks for the link, it definitely contributes to my understanding of the usage. – RG7 Feb 21 '20 at 6:42
2

I think that that setting is supposed to improve the user experience, not the "performance".

It should save you from having to run hash -r by hand when you moved or removed an executable.

Compare:

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

versus

bash$ shopt -s checkhash
bash$ mv second/ok first/ok
bash$ ok
ok
bash$ mv first/ok second/ok
bash$ ok
ok
bash$
2
  • The example clarifies the doubt. This looks like a good feature to enable; will definitely test this out. – RG7 Feb 21 '20 at 6:39
  • FWIW, the checkhash behaviour is the default in the zsh shell. – Kusalananda Feb 21 '20 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.