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!

getopts function

Status
Not open for further replies.

sfu

Programmer
Oct 13, 2003
10
US
I am running the GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu) Copyright (C) 2002 Free Software Foundation, Inc.

I tried to use the getopts function in my script. However, I always get the following error message:

./status: line 109: syntax error near unexpected token `;;'
./status: line 109: ` f ) flagf="TRUE";; '


while getopts ":fp" Option
do
case $Option in
f ) flagf="TRUE";;
p ) flagp="TRUE";;
* ) echo "Unimplemented option chosen."; exit 1;;
esac
done
shift $(($OPTIND - 1))

The code above works fine on an HP-UX machine, running the GNU bash, version 2.04.0(1)-release (hppa2.0w-hp-hpux11.00)
Copyright 1999 Free Software Foundation, Inc.

Can anybody give me a hint ?

Thanks!
 
I've tried it on all of these and it works fine...

[tt]GNU bash, version 2.05.8(1)-release (i386-redhat-linux-gnu)
Copyright 2000 Free Software Foundation, Inc.

GNU bash, version 2.03.0(1)-release (sparc-sun-solaris)
Copyright 1998 Free Software Foundation, Inc.

GNU bash, version 1.14.7(1)
Linux hostname 2.2.16-4.lfssmp #1 SMP Wed Jul 12 14:00:26 EDT 2000 i686 unknown[/tt]

It must be a bug in that particular version of bash?

Annihilannic.
 
Maybe try changing ":fp" to "fp". Or try removing the space character between the [fp] and the ')'. Is a non-built-in getopts available? You could always switch or even regress to using getopt.

Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
I tried all this, removing the ":" and the space charcters, still the same error message. Same thing happens with getopt.

Any other suggestions ?

Thanks!
 
Try putting a space in front of the ";;" on each line. Or put the ";;" on the next line by itself.

Some shells needs spaces to help parse the tokens.

Hope this helps.

 
I put the ;; seperate on each line ==> now it works!

Thanks to all of you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top