How to use set -A when first value is -x

How to use set -A when first value is -x

Post by Andrew Falang » Thu, 26 Aug 2004 07:13:38



Hi,

Well, I managed to work around this problem but I'd still like to know
what the answer is.  I'm sure there is one, I just couldn't get it.

I'm working on a script where there are both mandatory arguments and
optional args.  There is a point in a function that parses the command
line args.  It uses getopts to parse the options (I guess that was

At first I was using


Which worked just fine until I passed the script an option.  Then, I
continually got

parseCMDL[28]: -r: bad option(s)

How would I avoid this?

---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled.  I do not wish my account at HP to
become a spam haven.

 
 
 

How to use set -A when first value is -x

Post by Chris F.A. Johnso » Thu, 26 Aug 2004 08:27:13



> Hi,

> Well, I managed to work around this problem but I'd still like to know
> what the answer is.  I'm sure there is one, I just couldn't get it.

> I'm working on a script where there are both mandatory arguments and
> optional args.  There is a point in a function that parses the command
> line args.  It uses getopts to parse the options (I guess that was

> At first I was using


> Which worked just fine until I passed the script an option.  Then, I
> continually got

> parseCMDL[28]: -r: bad option(s)

> How would I avoid this?

    Don't create the array until you've parsed the options?

    Without seeing the script, I can't tell why you need an array; the
    arguments are already in an array: the positional parameters.

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

How to use set -A when first value is -x

Post by Kevin Rodger » Thu, 26 Aug 2004 08:44:58


 > I'm working on a script where there are both mandatory arguments and
 > optional args.  There is a point in a function that parses the command
 > line args.  It uses getopts to parse the options (I guess that was

 >
 > At first I was using
 >

 >
 > Which worked just fine until I passed the script an option.  Then, I
 > continually got
 >
 > parseCMDL[28]: -r: bad option(s)

It sounds like you forgot to shift after the getopts loop:

while getopts optstring vname; do
   case $vname in
     ...
   esac
done
shift OPTIND-1

--
Kevin Rodgers

 
 
 

How to use set -A when first value is -x

Post by Dan Merce » Thu, 26 Aug 2004 13:09:36


: Hi,
:
: Well, I managed to work around this problem but I'd still like to know
: what the answer is.  I'm sure there is one, I just couldn't get it.
:
: I'm working on a script where there are both mandatory arguments and
: optional args.  There is a point in a function that parses the command
: line args.  It uses getopts to parse the options (I guess that was

:
: At first I was using
:


The -- terminates the option list.  I would also suggest


so that ${ARGS[1]} = $1.  It can also be useful in error messages,
since $0 in a function MAY be the name of the function,  not the name
of the script.

Dan Mercer

:
: Which worked just fine until I passed the script an option.  Then, I
: continually got
:
: parseCMDL[28]: -r: bad option(s)
:
: How would I avoid this?
:
: ---------------------------------------------
: Andrew R. Falanga (a non-HP employee)
: Hewlett-Packard Company
: 11311 Chinden Blvd.
: Boise, Idaho
: ---------------------------------------------
: Please note: The e-mail address is purposely
: mangled.  I do not wish my account at HP to
: become a spam haven.

 
 
 

How to use set -A when first value is -x

Post by Stephane CHAZELA » Thu, 26 Aug 2004 15:39:31


2004-08-25, 04:09(+00), Dan Mercer:
[...]

> The -- terminates the option list.

[...]

Note that unfortunately, it doesn't work in zsh ksh emulation.

--
Stephane

 
 
 

How to use set -A when first value is -x

Post by Andrew Falang » Thu, 26 Aug 2004 23:36:27




>  > I'm working on a script where there are both mandatory arguments and
>  > optional args.  There is a point in a function that parses the command
>  > line args.  It uses getopts to parse the options (I guess that was

>  > At first I was using


>  > Which worked just fine until I passed the script an option.  Then, I
>  > continually got

>  > parseCMDL[28]: -r: bad option(s)

> It sounds like you forgot to shift after the getopts loop:

> while getopts optstring vname; do
>   case $vname in
>     ...
>   esac
> done
> shift OPTIND-1


Indeed I did forget the shift OPTIND step.

--

---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled.  I do not wish my account at HP to
become a spam haven.

 
 
 

How to use set -A when first value is -x

Post by those who know me have no need of my nam » Sat, 28 Aug 2004 19:25:19


in comp.unix.shell i read:

>2004-08-25, 04:09(+00), Dan Mercer:

>> The -- terminates the option list.
>Note that unfortunately, it doesn't work in zsh ksh emulation.

yet it should.  hopefully someone will report this bug.

--
a signature