Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to write a bash script, and would like it to parse unordered parameters of the format:

scriptname --param1 <string> --param2 <string> --param3 <date>

Is there a simple way to accomplish this, or am I pretty much stuck with $1, $2, $3?

edit

(note - I don't need long parameter names - single letters would be fine too)

share|improve this question
    
why did you post the same thing on stackoverflow and here? This is more programming related anyway. –  John T May 6 '09 at 3:34
1  
That is exactly why. –  Brent May 6 '09 at 3:46
add comment

2 Answers

up vote 9 down vote accepted

You should use getopt.

share|improve this answer
    
Thanks - That put me on the right track - I think that I actually want getopts - as it is apparently simpler, and I don't need the long names –  Brent May 6 '09 at 3:15
    
Cool, but you need to fix your question then :) It specifically lists long param names in the example. –  pjz May 6 '09 at 3:21
    
I edited the question, thanks. –  Brent May 6 '09 at 3:48
add comment

There are programmes already for doing that. getopt is the main one.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.