Handling "command not found" exception

hello friends,
I am given a project to handle the command not found exception.I am using RED HAT 9. Generally, when we press a wrong command in the terminal: example :-

" $cet " in place of " $cat ". Then we get this exception. But I need to give the output as the combinations that are possible with "cet". Example: "cat" or "cut" or any other possible command instead of just printing "command not found".

Can you please help me how to handle it. I am not able to decide how to start.:frowning:

U of course could modify the bash source code. if you to keep it simple define an alias for every posible failure:

alias fat="echo did you mean cat?"

of course there will be a lot of work to do.

I have seen also admins setting aliases to the correct command:

alias cet="cat"

so when a user types

$ cet ~/somefile

it will actually preform a "cat ~/somefile"

This is quite user specific however and must be changed for each user based on which commands they are more prone to "fat finger".

userA:
alias la="ls"

userB:
alias cet="cat"

userC:
alias cs="cd"

or use the "One to rule them all" Lord of the Rings mentality and place ALL of these aliases into one place "/etc/profile".

Another good approach if you use bash or any shell that can use tab completion really, is to USE tab completion!

so typing

ca<tab>

will list the commands/files that you can use..
EXAMPLE:
$ ce<tab>
certcgi certmgr certtool certutil cervisia

$ cat<tab>
cat catchsegv

Using this method will not only solve 99% of all "fat fingered" commands it can cut down on your typing by 50% or more most of the time.

take for example the command:

# cat /usr/local/bin/dosomestuff.sh

assuming that in the /usr/local/bin folder there is only 1 or 2 files starting with d and nothing starting with do other than our file...

# cat /u<tab>lo<tab>b<tab>do<tab>

reduces the characters you have typed from 33 to 15!

Sorry to double post but I remembered another nice tool (or rather shell).

As a shell give fish a try, it is VERY similar to bash but has a nice feature that actually color codes the command line as you type to indicate commands and files that are found or not.

As you are typing the word you are on will change from red to green if the command/file is found or not. It also does an underline to indicate files found. When using tab completion the whole line will flash another color if there is nothing found to complete the line.

Just wanted to add that as an option as well.

hello,
that "color" is a very nice idea.Can you please give me an example how to do it. So the color itself shall tell the user whether the command typed in is correct or not!!!!
Please give me an example.

fish is a shell like bash, sh, or tcsh... once installed you can either set that to your login shell in "/etc/passwd" or from your login shell type "fish" to switch to that shell.

If you have fish installed you and are logged into that shell, as you type the text will be red and as it recognizes the command all text will turn green.

For intance as I typed "ls", the letter l was red and when I hit the letter "s" the "ls" turned green.