Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 16th, 2007, 9:57 AM   #1
Silicon_Pudding
Newbie
 
Silicon_Pudding's Avatar
 
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0 Silicon_Pudding is on a distinguished road
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"
Silicon_Pudding is offline   Reply With Quote
Old Feb 16th, 2007, 10:37 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Are you using Bash?
Arevos is offline   Reply With Quote
Old Feb 17th, 2007, 11:19 AM   #3
Silicon_Pudding
Newbie
 
Silicon_Pudding's Avatar
 
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0 Silicon_Pudding is on a distinguished road
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"
Silicon_Pudding is offline   Reply With Quote
Old Feb 17th, 2007, 12:22 PM   #4
Serinth
Programmer
 
Serinth's Avatar
 
Join Date: Sep 2005
Posts: 50
Rep Power: 3 Serinth is on a distinguished road
You should look up GETOPTS in the advanced bash scripting guide.
__________________
A girl talked to me once.

http://www.latestanime.com
Serinth is offline   Reply With Quote
Old Feb 17th, 2007, 12:30 PM   #5
Silicon_Pudding
Newbie
 
Silicon_Pudding's Avatar
 
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0 Silicon_Pudding is on a distinguished road
Quote:
Originally Posted by Serinth View Post
You should look up GETOPTS in the advanced bash scripting guide.
Thanks, this is exactly what I was looking for.
__________________
~ Silicon Enhanced Pudding
"It's magically delicious"
Silicon_Pudding is offline   Reply With Quote
Old Feb 21st, 2007, 12:12 AM   #6
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
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.
a thing is offline   Reply With Quote
Old Feb 23rd, 2007, 9:22 PM   #7
a thing
Unverified User
 
a thing's Avatar
 
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0 a thing is on a distinguished road
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.
a thing is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:17 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC