![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help in getopts | chella | Shell Programming and Scripting | 4 | 11-02-2007 01:09 AM |
| getopts help | GrepMe | Shell Programming and Scripting | 3 | 06-20-2007 11:47 AM |
| getopts question!!! | andy2000 | Shell Programming and Scripting | 1 | 03-27-2007 12:15 AM |
| getopts | yerra | Shell Programming and Scripting | 5 | 03-26-2005 10:43 AM |
| getopts | Shell Programming and Scripting | 3 | 12-05-2002 07:42 PM | |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
question about getopts
hello there I am back with more questions (sorry it is been quite a while since I had done scripting). I had tried the search function to search for the threads that might have an answer to my question, but I could not find it, so I had decided to post it.
I had created the scripts below in ksh (assume the ksh file name is abc.ksh) -------------------------------------------------------------------------- var1=' ' var2=' ' while getopts ":a do case $opt in a) var1=$OPTARG;; b) var2=$OPTARG;; \?) echo "Invalid argument"; exit 1;; esac done shift 'expr ${OPTIND} - 1' echo "Statement" -------------------------------------------------------------------------- I ran the codes -------------------------------------------------------------------------- Server temp-> abc.ksh -a some_value -b other_value -------------------------------------------------------------------------- It works perfect, but if I ran the code with out the command line option -------------------------------------------------------------------------- Server temp-> abc.ksh some_value other_value Statement -------------------------------------------------------------------------- I thought if there are no -a or -b option is given, getopts would automatically faults out and abc.ksh would just display "Invalid Argument" and exit. Did I not doing this section of scripts correctly or I am just plain missing something? Thank you for your time |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|