如果从bash运行不存在的命令后在ubuntu中收到该消息,则您的系统可能正在使用command_not_found_handle
函数。您可以在中看到它/etc/bash.bashrc
。
可能有一些小小的黑客攻击:我刚刚创建了一个名为的脚本cnfh
:
#!/bin/bash
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -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" >&2
return 127
fi
}
fi
"$@"
RET_VAL=$?
if [ $RET_VAL -eq 127 ]; then
OUT=$(command_not_found_handle "$@" 2>&1)
$(echo $OUT |sed -n 's/.*\(apt-get install .\+\)$/\1/p')
fi
然后使用以下脚本运行td命令:
# ./cnfh td
使用Ubuntu 14.04.2 LTS。希望对您有所帮助。