Score:0

Command not found handler

ch flag

Apologies if this has been asked before, but it's basically impossible to search for.

When I type e.g. wibble at the bash prompt, it prints

Command 'wibble' not found, did you mean:
  command 'wobble' from deb emboss (6.6.0+dfsg-11ubuntu1)
Try: sudo apt install <deb name>

Now what I'd like to know is where is this handler and can I replace it with my own script. For example if I were to paste a github url at the command line with no 'git clone' before it, then expand it to 'git clone', and other urls launch in Chrome, or whatever.

I can't find where this 'command not found' hander is, but I suspect it's a script somewhere that gets hooked into bash.

guiverc avatar
cn flag
https://launchpad.net/ubuntu/+source/command-not-found *you didn't provide a release and I'm not going to look up the package version for `emboss` thus the link I provided.. Had I had a release I'd have provided link that was easier & showed the files involved... (*but you can follow links yourself*)
Cyrus avatar
cn flag
`set -x; wibble; set +x`?
Score:2
hr flag

The handler itself is a shell function:

$ declare -f -p command_not_found_handle 
command_not_found_handle () 
{ 
    if [ -x /usr/lib/command-not-found ]; then
        /usr/lib/command-not-found -- "$1";
        return $?;
    else
        if [ -x /usr/share/command-not-found/command-not-found ]; then
            /usr/share/command-not-found/command-not-found -- "$1";
            return $?;
        else
            printf "%s: command not found\n" "$1" 1>&2;
            return 127;
        fi;
    fi
}

The default handler in Ubuntu is defined in the /etc/bash.bashrc file. In turn, /usr/lib/command-not-found is a Python script provided by the command-not-found package.

John Allsup avatar
ch flag
Thanks. Exactly what I was after.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.