LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-23-2013, 05:08 PM   #1
ghborrmann
Member
 
Registered: May 2004
Location: Louisville KY
Distribution: Fedora 25
Posts: 32

Rep: Reputation: 0
How Does getopts Work with Combined Multiple Options?


I'm attempting to write a script to process options that might be combined; e.g.,
Code:
 myscript -abc
which designates the three options a, b, and c. I've found a number of getopts tutorials that explain how getopts works: it keeps track of where it is in the parsing by storing the next index in the variable OPTIND. This explanation is satisfactory in the situation where the options are all in separate words, but how does it know where it left off when processing a word like -abc with multiple options?
By testing with my own scripts, I've verified that OPTIND does not change after processing the first of the multiple options. I examined all the bash variables (using set), but I can't find any variable which could be responsible.
 
Old 12-24-2013, 03:57 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
getopts is a builtin so is not constrained to using variables which are visible to the shell user. Presumably it keeps what it needs to keep within the bash binary.
 
Old 12-25-2013, 03:40 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Does compgen -v show any more than set? set output is too verbose (mostly completion functions) to compare them.
 
Old 12-26-2013, 03:12 PM   #4
hoholala
LQ Newbie
 
Registered: Sep 2013
Distribution: Parabola GNU/linux-libre
Posts: 13

Rep: Reputation: Disabled
It's stored inside __nextchar: https://sourceware.org/git/?p=glibc....18;hb=HEAD#l47
A global copy of `struct _getopt_data' is declared at: https://sourceware.org/git/?p=glibc....5;hb=HEAD#l134

To understand how all this works, first read the headers:
https://sourceware.org/git/?p=glibc....3ab79c;hb=HEAD
https://sourceware.org/git/?p=glibc....18;hb=HEAD#l47

Then start from here: https://sourceware.org/git/?p=glibc....;hb=HEAD#l1187 and scroll up.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getopts long word options maddyfreaks Linux - Newbie 6 06-07-2012 06:21 AM
[SOLVED] getopts is not considering (skipping) one of the options akhand jyoti Linux - Newbie 3 11-18-2011 01:44 PM
How to use getopts to accept multiple parameters for a single option ? bittus Linux - Newbie 1 09-04-2009 01:38 AM
Passing command line arguments through getopts and long options neville310 Programming 3 04-16-2007 06:38 AM
getopts multiple parameters arnulfo Programming 2 12-23-2004 05:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration