gk@Jarvis:~$ sudi
No command 'sudi' found, did you mean:
Command 'sudo' from package 'sudo-ldap' (universe)
Command 'sudo' from package 'sudo' (main)
sudi: command not found
我目前已经实现了一个简单的“你的意思是..?”对于简单的英语单词,其工作方式如下:
- 如果用户输入“Kack”,请在 QWERTY 键盘上检查单词中每个字母周围的字母,然后将它们一一替换。 (例如,在这里它们将是 J、L、M、I、O 表示“K”;Q、W、S、Z、X 表示“a”等等)
- 根据对文本语料库的训练,返回最有可能的词(如果是这种情况,用户也输入词本身)作为最有可能的词。
如何在 linux 命令行中实现代码建议?
最佳答案
bash
没有实现建议逻辑;它位于定义为 bash 初始化文件一部分的函数中,并且由您的发行版(猜测是 Ubuntu/Debian)放在那里。
bash
提供了实现这样一个功能的机制:当它试图执行一个命令,但没有找到该命令时,它调用函数 command_not_found_handle
,如果它已定义。
在我的机器(一个 Ubuntu 变体)上,该函数定义如下:
$ type command_not_found_handle
command_not_found_handle is a function
command_not_found_handle ()
{
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1";
return $?;
else
if [ -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" 1>&2;
return 127;
fi;
fi
}
(并且 /usr/lib/command-not-found
存在,是可执行的,并且是一个 Python 脚本。)
关于bash - 命令建议在 bash shell 中是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35712703/