Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 为bash设置默认命令_Linux_Bash_Shell_Command Line_Command - Fatal编程技术网

Linux 为bash设置默认命令

Linux 为bash设置默认命令,linux,bash,shell,command-line,command,Linux,Bash,Shell,Command Line,Command,假设我创建了自己的脚本,并且希望该脚本成为在未找到命令时执行的默认命令,那么如何配置bash来实现这一点呢 该命令称为defCMD 假设我在命令行中键入一些随机字符串: $ viosjaldfksajflsfa 通常,它会输出“未找到viosjaldfksajflsfa” 但是,我希望将“viosjaldfksajflsfa”作为参数输入到我编写的defCMD脚本中,从而让bash执行defCMD,而不是这样 有没有办法做到这一点 My bash(Fedora)有以下功能 $ type com

假设我创建了自己的脚本,并且希望该脚本成为在未找到命令时执行的默认命令,那么如何配置bash来实现这一点呢

该命令称为defCMD

假设我在命令行中键入一些随机字符串:

$ viosjaldfksajflsfa
通常,它会输出“未找到viosjaldfksajflsfa”

但是,我希望将“viosjaldfksajflsfa”作为参数输入到我编写的defCMD脚本中,从而让bash执行defCMD,而不是这样

有没有办法做到这一点

My bash(Fedora)有以下功能

$ 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/libexec/packagekitd ] && runcnf=0;
    if [ $runcnf -eq 1 ]; then
        /usr/libexec/pk-command-not-found $@;
        retval=$?;
    else
        echo "bash: $1: command not found";
    fi;
    return $retval
}

您可以从这里开始,将其添加到
.bashrc
文件中。更改
else
分支。

命令\u not\u found\u handle
是在
bash
4.0中引入的,但我认为大多数Linux发行版现在已经升级到了4.x系列中。