BASH command_not_found_handle() - 不建议解决方案

时间:2012-08-16 15:24:07

标签: bash built-in

我想让command_not_found_handle在我的Scientific Linux中工作。我安装了command-not-found

`sudo yum install PackageKit-command-not-found.x86_64` 

现在,如果我发出type command_not_found_handle,我会:

[JmZ:/usr/lib]-->type command_not_found_handle
command_not_found_handle is a function
command_not_found_handle ()
{
    runcnf=1;
    retval=127;
    [ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0;
    [ ! -x /usr/sbin/packagekitd ] && runcnf=0;
    if [ $runcnf -eq 1 ]; then
        /usr/libexec/pk-command-not-found $1;
        retval=$?;
    else
        echo "bash: $1: command not found";
    fi;
    return $retval
}

我在安装软件包之前没有看到。如果我现在为某些未安装的程序(例如gcl)发出命令,我只是得到以下内容:

[JmZ:/usr/lib]-->gcl
Command not found.

如果我在Ubuntu中做类似的事情,我会得到:

JmZ@ubuntu:~$ gcl
The program 'gcl' is currently not installed.  You can install it by typing:
sudo apt-get install gcl

我想在Scientific Linux中获得类似的功能。我该如何设置?

感谢。

1 个答案:

答案 0 :(得分:1)

目前我正在运行Linux Mint,版本介于14到16之间,我的command_not_found_handle就是这样:

command_not_found_handle is a function
command_not_found_handle () 
{ 
    if [ -x /usr/lib/command-not-found ]; then
        /usr/bin/python /usr/lib/command-not-found -- $1;
        return $?;
    else
        return 127;
    fi
}

该脚本引用this page,其中有一个tarball下载应该包含您需要的所有内容。