【发布时间】:2015-02-17 18:51:09
【问题描述】:
所以我的 .bashrc 文件中有这个 bash 代码...我使用的是 Mac OS X Yosemite
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 "lalalla";
retval=1;
fi;
return $retval
}
我之前在 linux 环境中使用过这段代码,它工作得很好......当用户输入一个不存在的 bash 命令时,它会默认通过回显“lalalal”......但是当我在我的 Mac OS X Yosemite 上使用它,尽管我的 .bashrc 文件已正确注册(我已执行 source ~/.bash_profile 并且我的 .bash_profile 包含代码 source ~/.bashrc
我的 .bashrc 中存在的其他命令执行得很好......
我做错了什么?当用户输入 mac 中不存在的命令时,如何让 mac 使用 command_not_found_handle?
更新
@tristan 所以我通过 brew 升级了 bash,当我运行 bash --version 输出时得到确认
GNU bash, version 4.3.30(1)-release (x86_64-apple-darwin14.0.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
此外,我重做了源 .bash_profile
但是当我输入一个不存在的命令时它仍然显示
-bash: askldfasf: command not found
我做错了什么?
【问题讨论】:
-
次要备注:
return $retval错误:return只返回数字参数。
标签: linux macos bash shell command-line