--> Can't quite figure out getopts <--

--> Can't quite figure out getopts <--

Post by David Whi » Sat, 29 Mar 1997 04:00:00

Suppose I have a program "foo" which has the following syntax:

foo [-h] [-r] [-d[1|2|3]] [-l [filename]] filename

and I want to use "getopts" to process it.  Obviously, handling the
-h and -r options are easy, but what about the other two?

The -d option can be used by itself, or else it can be set to some
level (e.g. -d1, -d2, -d3).  Is there a way to process this with
getopts, without having to separate the values into -d 1, -d 2, -d 3

But more importantly, what about the last option?  -l can be used by
itself, or it can have an optional filename (e.g. "-l" or
"-l bar.sh")  Is there a way to tell getopts that -l MIGHT have a
OPTARG, but also may not?

(I'm afraid the answer to this might be "No, because getopts has no
way of knowing whether the value that follows -l is the optional
argument of -l, or the filename that you're runing "foo" on.  But
even if that's true, can anyone suggest a workaround?  For instance,
what method do programmers use when they set up variables and
arguments that AREN'T separated by spaces? )
        (e.g. "foo -h -d1 -l/usr/data/bar.sh  baz.sh")

Thanks to anyone who can help!



I have a 10 GB UDMA IDE drive formatted with Windows.  The first partition
is FAT32, and the second is NTFS.  I can successfully mount the first, but
not the second.  Any ideas?

Suse 7.2 on i86
the drive is mounted on /dev/hdc, and I CAN see hda1, but not hda2

2. SCSI problem

3. Wanted: <><><> Unix Specialist <><><>

4. Promise RAID on Microstar motherboard

5. LILO help <><><><><><>

6. Piping stderr

7. ----->>>XF86Config Help Needed Here's a Copy of<<<------

8. Serial connection problems

9. <Alt>+<key> = <Esc><key> ?

10. *{<><>}*Linux*Screen*Difficulties*{<><>}*

11. << <<anyone using dyn-html?>> >>

12. (<><>)*Linux*Screen*Difficulties*(<><>)

13. Samba problem: WinXP <-> ADSL <-> Internet <-> Cable <-> Linux