help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How bash is hijacked to prompt useful help when the comm


From: Davide Brini
Subject: Re: [Help-bash] How bash is hijacked to prompt useful help when the command is not found?
Date: Sat, 31 Mar 2012 11:05:10 +0200

On Sat, 31 Mar 2012 03:58:57 -0500, Peng Yu <address@hidden> wrote:

> Hi,
> 
> On mac, when I type an unknown command (in bash), it just shows an error.
> 
> ~$ xxx
> -bash: xxx: command not found
> 
> But on ubuntu, it can prompt something more useful (above "xxx:
> command not found").
> 
> ~$ xxx
> No command 'xxx' found, did you mean:
>  Command 'xdx' from package 'xdx' (universe)
>  Command 'x2x' from package 'x2x' (universe)
>  Command 'xx' from package 'fex-utils' (universe)
>  Command 'xxd' from package 'vim-common' (main)
> xxx: command not found
> 
> If I try the same thing in ksh in ubuntu, it clearly shows that the
> prompt is different. So the conclusion is that somehow bash is hijack
> in ubuntu to print more helpful statements. Does anybody know how this
> is done?

As usual, the answer is in the man page, under "COMMAND EXECUTION":

...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, and the function's exit status becomes the exit status of
the shell.

This should get you started:

declare -f | awk '/command_not_found_handle/,/^}/'

-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]