Bypass getopts errors and continue processing?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bypass getopts errors and continue processing?
# 1  
Old 08-05-2011
Bypass getopts errors and continue processing?

Is there a way to do this?

while getopts "n:g:m:i:p:d:a:" OPTION
   case $OPTION in

if i do a ./ -n john -u user -p password, it will output:

 name= john
./ illegal option -- u

Is there a way to skip over errors so that -p will get processed as well?

By the way, ./ -n john -u -p password will output:
./ illegal option --u

so I'm guessing the option with -u is the problem?
# 2  
Old 08-05-2011
Why don't you just add 'u:' to getopts?

while getopts "n:g:m:i:u:d:a:" OPTION

# 3  
Old 08-05-2011
Please when asking about shell programming specify your system, the first line of your script, shell you use, version of your shell, and give a working (or not working but full) example of your script.
# 4  
Old 08-05-2011
I don't want a -u. And also, i'd want to handle cases where the user might input a wrong parameter with an option...
# 5  
Old 08-05-2011
Are you saying you want to print a nice error message when the user enters an invalid option?
# 6  
Old 08-05-2011
no, it already does print an error message, but it doesn't continue processing the rest of the arguments after the error...
# 7  
Old 08-05-2011
I'd suggest that the script should exit if the user enters an invalid option.

However, I can think of a way around this.

---------- Post updated at 09:20 AM ---------- Previous update was at 09:11 AM ----------

Try this:
add the ':' at the begining of getopts.
add ?) to the case statement and do what you want in there.

while getopts ":dhqTv" OPT                              # While there is a command line option
   case $OPT in

      h)   print_options;;




      ?)   print_status_message "ERROR: Unknown flag encountered.\n" ERROR


done                                            # end -

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bypass crontab??

Hi there. I've put something in crontab that my raspberry doesn't like, it's trying to draw a window before the graphics are ready after login. Problem being after the error it throws me back to the login, so I can't log in. There is only one user setup on this raspberry so I can't log in... (6 Replies)
Discussion started by: MuntyScrunt
6 Replies

2. Shell Programming and Scripting

Continue Processing after a signal is caught

Is it possible to continue after signal is caught and control goes to function specified in the trap statement? (3 Replies)
Discussion started by: Soham
3 Replies

3. HP-UX

Bypass stale PE ?

Hello, I have an ancient HP-UX 11.11 system where I have a logical volume marked stale and I can't get it sync'd. I have tried lvsync and lvreduce/lvextend to no avail. It is just one 4Mb PE on the disk that I can't get current. # lvdisplay -v /dev/vg00/lvol5 | grep stale LV Status ... (17 Replies)
Discussion started by: port43
17 Replies

4. Programming

Need program to continue even when encountering errors

I am writing a program, and want to have the option for the program to continue execution even should things go wrong. I use an option --ignore-errors. The problem is what I do when an error occurs, set the values to zero, or fill them up with some values, for example taken from a simple unit... (3 Replies)
Discussion started by: kristinu
3 Replies

5. Shell Programming and Scripting

awk Division By Zero Bypass

Hi Friends, I don't understand why "a" is always being printed as zero, when I execute the following command. awk '{if($6||$8||$10||$12==0)a=b=c=d=0;else (a=$5/$6);(b=$7/$8);(c=$9/$10);(d=$11/$12); {print... (6 Replies)
Discussion started by: jacobs.smith
6 Replies

6. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

7. Cybersecurity

authentication bypass vulnerability

what does it mean? I searched in google but I could not find a clear document that explain to me what does it mean. (1 Reply)
Discussion started by: programAngel
1 Replies

8. Solaris

can't bypass password authentication

I can able to SFTP from my web server unix to apps server unix end. but the other way from APPS server to Web server is still asking me the password. I have done same procedure both side. still i am having same problem. Any one help on this. thanks, regards (3 Replies)
Discussion started by: vijill
3 Replies

9. Shell Programming and Scripting

How can I bypass the Prompt in SFTP

I am on a sun solaris server and trying to create a script that will test if SFTP is up and running on a remote server (which could be unix or windows). My thought was to simply invoke sftp and if I get the prompt ofr "Password" then that is an indication that the service is running and I am... (2 Replies)
Discussion started by: pierluigi22
2 Replies
Login or Register to Ask a Question