1

When I mistype command in terminal I got this error:

bash: XX: command not found...

After that, I have to wait or use keyboard interrupt before I can use prompt again. Sometimes shell offers me to install some command and that's quite annoying.

Is there any way to get rid of this delay?

Thanks for answers

EFK
  • 25

2 Answers2

4

The delay is caused by a custom command-not-found handler added by your distribution. It is usually added somewhere in the system-wide /etc/bash.bashrc file.

The handler is just a shell function with a specific name, so you can also disable or override it via ~/.bashrc (e.g. if you don't want to change the system-wide config).

If the distro's handler is being too slow, then you can simply remove (unset -f) the function and return to bash's standard behavior:

unset -f command_not_found_handle

On the other hand, if you don't like the message, then you can define your own version of the handler (again via ~/.bashrc):

command_not_found_handle() {
    echo "I don't know what '$1' is." >&2
    return 1
}
grawity
  • 501,077
1

Another method is to uninstall the package that provides the executable pk-command-not-found -- on my Rocky Linux 9 the command_not_found_handle looks like this:

command_not_found_handle () 
    [[ ! -x '/usr/libexec/pk-command-not-found' ]] && runcnf=0;
        '/usr/libexec/pk-command-not-found' "$@";
            printf 'bash: %scommand not found\n' "${1:+$1: }" 1>&2;

So you can see that it's dependent on that /usr/libexec/pk-command-not-found executable.

On a Red Hat-like system, you can do this to find out what package it is and uninstall it:

# rpm -qf /usr/libexec/pk-command-not-found
PackageKit-command-not-found-1.2.4-2.el9.x86_64
# dnf remove PackageKit-command-not-found

This changes it system-wide, all users would be affected.

Oh, and 2>&1 is just bash file handle redirection. It literally means "send my stderr to the same thing as stdout".

Jeff
  • 11
  • 2