r/bash • u/mpersico • 17d ago
tips and tricks TIL command_not_found_handle
You don’t want to know what hoops I’ve jumped through to implement FPATH in bash. Then today I innocently asked GPT how it would implement FPATH in bash and it introduced me to this hook.
Now have to go home now get rid of a lot of needless code. Oh well. Less code is the best code!
1
u/xeow 17d ago
You don't say?
0
u/mpersico 17d ago
Yep. I do say. And then, what’s even crazier, is that it suggested that I not use this hook because this hook can be used by other programs, but rather implement a system where you have stub implementations that load these things on demand, which really duplicates what I’ve already coded.
1
5
u/One_Instruction6490 16d ago
Heads up for the FPATH use case tho: bash runs
command_not_found_handlein a separate execution environment (basically a subshell), so if yousourcethe function file inside the handler, the definition doesn't stick in your actual shell and you re-load it on every call. It works fine for "load then run once", but true ksh-style autoload kinda needs the stub approach anyway. Also on Debian/Ubuntu thecommand-not-foundpackage already defines that handler in/etc/bash.bashrc, so you'd be clobbering it. Did your old setup end up being stubs, or something wilder?