dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

passing options to a shell script - bsd.freebsd.misc

This is a discussion on passing options to a shell script - bsd.freebsd.misc ; Hi, im trying to write a script that will accept two options out of a list of 5 options. The first set of options comprise --test, --real and -- verbose, the second set of options comprises --months and --year and ...


Home > Database Forum > Operating Systems > bsd.freebsd.misc > passing options to a shell script

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 09-16-2007, 12:17 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default passing options to a shell script

Hi,

im trying to write a script that will accept two options out of a list
of 5 options. The first set of options comprise --test, --real and --
verbose, the second set of options comprises --months and --year and
it takes variables for each.

What i am trying to accomplish is, when any one of the first set of
variables is passed, a second from that set cannot be passed, and when
an attempt to pass more than one option from the first set an error is
given. the same applies to the second set of options.

I am using getopts to get the options, but failed to find a way to
restrict usage of only one option from the two sets of options.

any guidance appreciated.

Regards,

Mike

Reply With Quote
  #2  
Old 09-16-2007, 01:47 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: passing options to a shell script


barnard wrote:

> Hi,
>
> im trying to write a script that will accept two options out of a list
> of 5 options. The first set of options comprise --test, --real and --
> verbose, the second set of options comprises --months and --year and
> it takes variables for each.
>
> What i am trying to accomplish is, when any one of the first set of
> variables is passed, a second from that set cannot be passed, and when
> an attempt to pass more than one option from the first set an error is
> given. the same applies to the second set of options.
>
> I am using getopts to get the options, but failed to find a way to
> restrict usage of only one option from the two sets of options.


After parsing the options, just check wether you have seen options
from both mutually exclusive sets. Like

if test -n "$DATE" && test -n "$MODE"; then ....


> any guidance appreciated.


My pleasure.

Regards - M
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 12:38 PM.