Hacker News new | ask | show | jobs
by ktm5j 130 days ago
I'm on my phone so I'm too lazy to dig for this, but I'm pretty sure they're talking about the bit of shell script that gets run if you type a command that isn't found in PATH.

Fedora and Debian will both dive straight into searching apt/dnf for a matching package and ask "do you want to install this?"

I imagine you could create a hook that gets run for any command failure, but again I'm on my phone so not sure.

4 comments

This is generally called a command-not-found handler and are a feature of all the major shells (though the exact details differ, the general idea is to define a function with a specific reserved name), and most majors distros have ones that can be installed, even if they aren't by default.

I wrote my own (much faster) such handler for Arch Linux. I even wrote a blog post about the design: https://vorpal.se/posts/2025/mar/25/filkoll-the-fastest-comm...

I thought of that, but TFA describes a system that trips on incorrect filenames rather than just incorrect commands.
I vaguely remember that there are hook functions for processing all entered lines as well (at least for zsh), but it isn't something I have used myself so I know nothing more than that.
which is run by bash in the way I described.

In /etc/bash.bashrc:

# if the command-not-found package is installed, use it if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then ... fi

I thought Ubuntu did that, but not Debian. Still, that's very different than what the author mentioned
Oh you might be right about Ubuntu vs Debian.. but I'm right about everything else I said. I went and looked at the source code.
cachy's setup of fish tries to suggest commands (and even arguments) it might be, which I find terrifying and so turn off.