Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone know what this is ? getopts....

Status
Not open for further replies.

maxcrook

Programmer
Jan 25, 2001
210
GB
Please can someone explain what the following part of a script is doing please.

Nb: BILL_DATE is defined by user input via an application

BILL_DATE=""

# check parameters
while getopts ":p:m:c:t:w:r:a:" opt
do
case "$opt" in
p) ;;
m) ;;
c) ;;
t) ;;
w) ;;
r) ;;
a) BILL_DATE=$OPTARG;;
\?) echo "\nERROR: Invalid parameter passed"
exit 1;;
esac
done
 
Max,

there's a pretty good manpage on getopts.

I'd post it here, but it's fairly long.

Hope this helps.
 
Thanks Ken I can work out the basics to it but cant understand how it has been worked in this particular context.
 
Simple.

Your script is checking at its options. [tt]getopts[/tt] is handling errors and storing them (the first colon), Uses one character options (pmctwra) , and each can receive parameters. Just that.
I hope it works...
Unix was made by and for smart people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top