![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0
![]() |
what is the best method for reading in arguments?
what is the best method for reading in arguments? How do you guys usually do it?
For example if I had stuff like -r 432 -t -i 5435 etc.
__________________
~ Silicon Enhanced Pudding "It's magically delicious" |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
Are you using Bash?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0
![]() |
yes. i'm using bash.
I want to read in multiple arguments of unknown length. I found one way that uses a loop with the argument count $#, then uses a case statement to evaluate $1, and then shifts the arguments over to look at the next one. I was just wondering if there were other methods.
__________________
~ Silicon Enhanced Pudding "It's magically delicious" |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Sep 2005
Posts: 50
Rep Power: 3
![]() |
You should look up GETOPTS in the advanced bash scripting guide.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0
![]() |
Thanks, this is exactly what I was looking for.
__________________
~ Silicon Enhanced Pudding "It's magically delicious" |
|
|
|
|
|
#6 |
|
Unverified User
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0
![]() |
getopts isn't very powerful. Take a look at how prefix (specifically sections 2 through 4) parses arguments. If you want another example, look at fsize.
Note this system is imperfect. Most notibly it doesn't yet support non-option arguments that start with a hyphen. I'll get to this when I have time (a lot of stuff builds up to read after being away over a three day weekend...). I should make a shell based off Bash that incorporates this system in a builtin...
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted. Got 'Nux?—GNU/Linux and other free software support. It's GNU/Linux, not just Linux. Last edited by a thing; Feb 21st, 2007 at 12:31 AM. |
|
|
|
|
|
#7 |
|
Unverified User
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0
![]() |
Okay, I've updated fszie to handle files that start with a hyphen (you have to put -- first to tell it to stop parsing options).
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted. Got 'Nux?—GNU/Linux and other free software support. It's GNU/Linux, not just Linux. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to invoke static method from a Class object? | smith.norton | Java | 1 | Oct 5th, 2006 3:00 AM |
| Combining languages | titaniumdecoy | Other Programming Languages | 12 | Jul 13th, 2006 2:03 PM |
| DiveLog.java tutorial help | Arenlor | Java | 2 | Apr 26th, 2006 10:11 AM |
| Median/Mode in arrays? {Need help} | Java|Tera | Java | 27 | Nov 29th, 2005 10:50 AM |
| Debug recursion method() | pr0gm3r | Java | 3 | Oct 11th, 2005 12:33 PM |