Handling "command not found" exception


 
Thread Tools Search this Thread
Operating Systems Linux Handling "command not found" exception
# 1  
Old 12-02-2008
Bug 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.Smilie
# 2  
Old 12-03-2008
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.
# 3  
Old 12-05-2008
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!

Last edited by ddreggors; 12-05-2008 at 02:24 AM..
# 4  
Old 12-05-2008
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.
# 5  
Old 12-13-2008
Bug

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.
# 6  
Old 12-18-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Problem on SQLplus command ""bash: sqlplus: command not found""

Hi all, i face an error related to my server ""it's running server"" when i use sqlplus command $ sqlplus bash: sqlplus: command not found the data base is up and running i just need to access the sqlplus to import the dump file as a daily backup. i already check the directory... (4 Replies)
Discussion started by: clerck
4 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Bash Script giving "Command Not found"

Hello Geeks, Greetings...I have the following script: #!/usr/bin/bash #Script to generate number of active PDP context & calculate PDP activation #failurefrom EPG-M #Script written by Gbenga Adigun #September 12, 2013 username="xxxxxx" password="xxxxxxxxx" HOSTS=( ggsn01... (6 Replies)
Discussion started by: infinitydon
6 Replies

4. Shell Programming and Scripting

"Command not found" doing a while loop in bash/shell

i=0 numberofproducts=${#urls} #gets number of entries in array called "urls" numberofproductsminusone=`expr $numberofproducts - 1` #-subtract by one while do wget ${urls} i=$(( $i + 1 )) sleep 10 done I'm getting an error ./scrape: line 22: [0: command not found that... (3 Replies)
Discussion started by: phpchick
3 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Post Here to Contact Site Administrators and Moderators

What's happens with my thread about "-bash: ELF: command not found "?

Hi, Today, I've submitted a new tread in "Shell Programming and Scripting" forum, with title "-bash: ELF: command not found ". However, this thread has disappear. Can somebody give me an explanation? Regards. (3 Replies)
Discussion started by: Sonia_
3 Replies

7. Shell Programming and Scripting

How to distinguish between "command not found" and "command with no result"

system() call imeplemented in solaris is such a way that: Command not found - return code 1 Command executed successfully without Output - return code 1 how to distinguish between these two based on return code in a c - file? Can you help on this ? (5 Replies)
Discussion started by: iitmadhu
5 Replies

8. Shell Programming and Scripting

"-bash: sqlldr: command not found"

hi all, here i am trying to run one control file. but getting "-bash: sqlldr: command not found" error :confused: the code is given below. sqlldr $db_username/$db_password@$db_sid control=$loading_path/load_to_table.ctl log=loading.log can anybody help me in fixing the issue? ... (1 Reply)
Discussion started by: vinayakatj56
1 Replies

9. UNIX for Dummies Questions & Answers

why emacs caused "command not found" error

I installed Red Hat Enterprise Linux 5 on my PC. When i typed 'emacs' on the console, "command not found" error occurrd. Why. :mad: (1 Reply)
Discussion started by: cy163
1 Replies
Login or Register to Ask a Question