explanation of getops | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

explanation of getops

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-06-2008
cesarNZ cesarNZ is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 21 June 2011, 8:35 PM EDT
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
explanation of getops

hi all,
i am trying to figure out what exactly does this chunk of code which sits in a shell script does. Am not very good at scripting so could someone explain what the below is/does ?? its a ksh (i.e #!/bin/ksh) and sits on a solaris 9 box.


REFRESH=FALSE

((C=0))
while getopts vrb:c:f: OPT
do
case $OPT in
r|-r) REFRESH=TRUE; ((C+=1)) ;;
esac
done




thanks in advance,
Cesar.
Sponsored Links
    #2  
Old 05-06-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
 
Join Date: Aug 2007
Last Activity: 2 October 2012, 1:31 PM EDT
Location: Bangalore
Posts: 390
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by cesarNZ View Post
hi all,
i am trying to figure out what exactly does this chunk of code which sits in a shell script does. Am not very good at scripting so could someone explain what the below is/does ?? its a ksh (i.e #!/bin/ksh) and sits on a solaris 9 box.


REFRESH=FALSE

((C=0))
while getopts vrb:c:f: OPT
do
case $OPT in
r|-r) REFRESH=TRUE; ((C+=1)) ;;
esac
done




thanks in advance,
Cesar.
getopts is used for parsing for the arguements. The colon specifies that it requires an arguement. Here in your code if you specify the option b or c or f , then it is must that you pass the respective arguements to them.

$OPT is used for the option you are choosing. here if u choose the option r ot -r then setting the flag to true and increasing the count.

do a
Code:
man getopts

Thanks
Sponsored Links
    #3  
Old 05-06-2008
cesarNZ cesarNZ is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 21 June 2011, 8:35 PM EDT
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
thanks, that clears up a few things.

ta.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need explanation for $PS1, $PS2, $PS3, $PS4 ramserp Shell Programming and Scripting 6 03-05-2010 07:30 AM
In need of explanation Lillyt UNIX for Dummies Questions & Answers 1 11-20-2009 12:27 AM
need explanation Mari.kb UNIX and Linux Applications 1 11-23-2007 09:41 AM
tr explanation please convenientstore Shell Programming and Scripting 1 05-30-2007 11:42 PM
tr explanation please convenientstore Shell Programming and Scripting 0 05-30-2007 11:12 PM



All times are GMT -4. The time now is 11:51 AM.