Home » Questions » Computers [ Ask a new question ]

Is there a typo corrector for bash?

Is there a typo corrector for bash?

I'd like for something to hook into the 'command not found' error on bash and offer a useful fix.

Asked by: Guest | Views: 21
Total answers/comments: 2
Guest [Entry]

"I don't know of a general purpose one, but there is one for directory names:

$ shopt -s cdspell
$ cd /usr/ibn
$ pwd
$ cd /usr/shar/doc

This is from the man page for Bash:

If the search is unsuccessful, the shell searches for a defined shell
function named command_not_found_handle. If that function exists, it is
invoked with the original command and the original command's arguments
as its arguments

It might be possible to use this to do what you want, but the code would be quite a challenge. By the way, Ubuntu, for example, uses this to display packages that contain the command that was not found with installation instructions (apt-get)."
Guest [Entry]

"the command-not-found package should provide this feature in recent distros.

If not, you can invoke it manually from the command_not_found_handle() function.

Another alternative is this."