The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Using getopts TurboArkhan Shell Programming and Scripting 3 06-22-2009 05:31 PM
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 12:47 PM
help in getopts problems Shell Programming and Scripting 1 05-05-2006 12:07 AM
getopts google Shell Programming and Scripting 3 12-05-2002 07:42 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-09-2009
som.nitk som.nitk is offline
Registered User
  
 

Join Date: Nov 2008
Location: Pune, India
Posts: 23
using getopts

Hi,
I have a program where I want to use getopts.
I want to use "-i" option and then optionally supply arguments.
If user dosent supply arguments, then also it should work.
Please tell me how to proceed.
Here is some code, this is not right code btw but a sample to understand what I want to do:

Code:
while getopts :tui:c:p: swtch
        do
                case $swtch in
                        u) echo "Un-installing feature is under development.";;
                        i)
                                echo $OPTARG
                                if [[ $OPTARG = "" ]]
                                then
                                      ValidateInput
                                else
                                       ValidateInput ${OPTARG}
                       \?) usage ;;
                esac
        done
        shift $(($OPTIND -1))
  #2 (permalink)  
Old 07-09-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,930
Remove the ':' from after the 'i' in your list of command line switches.
Its all explained in the man page for getopts
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0