Old 2nd March 2007, 22:49
alexus alexus is offline
Junior Member
Join Date: Jan 2007
Location: Brooklyn, NY
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to alexus Send a message via AIM to alexus Send a message via MSN to alexus Send a message via Yahoo to alexus Send a message via Skype™ to alexus
Default getopts


i'm writing shell script and i'm at the point where i need getopts help
how can i use getopts and have multiple arguments (some of them is required and some of them is optional)? for instance.

i need to run shell with following arguments:

--host/ip [host/ip]
--file-list [file-list]

here i also need to run either of those, not together... but one parameter is required, and if someone just run it with --sleep that wouldn't be sufficient since --host/ip or --file-list wasn't specified..

--sleep [time]
--status [print out status]

from what I've Google'ed, all examples only shows you how to take 1 parameter and work with it, but i didn't find any where it would show you how to take more then one and in one case make something required

sounds complicated i know
Reply With Quote
Sponsored Links
Old 3rd March 2007, 17:02
falko falko is offline
Super Moderator
Join Date: Apr 2005
Location: Lneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,752 Times in 2,582 Posts

You can reference parameters in a script with $1, $2, $3, ...

For example, if you run a script like this:
./myscript.sh paramter1 parameter2
then $1 contains parameter1, and $2 parameter2.
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Old 25th March 2007, 01:23
insistkool insistkool is offline
Junior Member
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to insistkool

try perl Getopt module, very easy to use

Reply With Quote


Thread Tools
Display Modes

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

Forum Jump

All times are GMT +2. The time now is 11:32.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.