Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   what is the best method for reading in arguments? (http://www.programmingforums.org/showthread.php?t=12586)

Silicon_Pudding Feb 16th, 2007 9:57 AM

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.

Arevos Feb 16th, 2007 10:37 AM

Are you using Bash?

Silicon_Pudding Feb 17th, 2007 11:19 AM

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.

Serinth Feb 17th, 2007 12:22 PM

You should look up GETOPTS in the advanced bash scripting guide.

Silicon_Pudding Feb 17th, 2007 12:30 PM

Quote:

Originally Posted by Serinth (Post 124069)
You should look up GETOPTS in the advanced bash scripting guide.

Thanks, this is exactly what I was looking for.

a thing Feb 21st, 2007 12:12 AM

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...

a thing Feb 23rd, 2007 9:22 PM

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).


All times are GMT -5. The time now is 9:59 PM.

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