$ bash ./test-command-exists.bash
current shell is bash
type:
real 0m1.791s
user 0m0.610s
sys 0m1.176s
hash:
real 0m1.989s
user 0m0.495s
sys 0m1.488s
command -v:
real 0m1.756s
user 0m0.529s
sys 0m1.222s
$ zsh ./test-command-exists.bash
current shell is zsh
type:
real 1.15s
user 0.29s
sys 0.85s
hash:
real 0.53s
user 0.21s
sys 0.32s
command -v:
real 1.15s
user 0.29s
sys 0.85s
(( $+commands[$cmd] )):
real 0.08s
user 0.08s
sys 0.00s
Whenever I install a new package in a zsh session,
I need to manually run hash -r to make autocomplete work for the new command.
Zsh very likely has a caching mechanism for available commands internally.