The UNIX and Linux Forums  

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




Thread: using getopts
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #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))