From: Useko Netsumi Date: 2003-02-20T00:51:25+09:00 Subject: Re: Ruby scripts for daily unix system administration Thanks for the example. I got it to works with a very minor correction(put $ on variable name,e.g. $count, $blocksize, and $filename). Suppose that I accidently put -g instead of -c, instead of giving me an error, it should just ignore it, just like an *) in the 'case' statement for everything else it does not understand Thanks "Tom Payne" wrote in message news:6756066a.0302190627.754e22f9@posting.google.com... > "Useko Netsumi" wrote in message news:... > > Thank you, but its a bit advance for me. I'd like to start on how to parse > > arguments from a shell scripts such as the following: > > > > usage: mktmpswap -c c0 -b b0 -f f0 > > The getoptlong and optparse modules are your friend. They both parse > command line arguments but are quite different in design. getoptlong > is easier to use, but optparse is allegedly more powerful. > > Getoptlong example: > > -----8<----- > require 'getoptlong' > > count = blocksize = filename = nil # default values > GetoptLong.new( > ['-c', GetoptLong::REQUIRED_ARGUMENT], > ['-b', GetoptLong::REQUIRED_ARGUMENT], > ['-f', GetoptLong::REQUIRED_ARGUMENT]).each do |opt, arg| > case opt > when '-c' then count = arg > when '-b' then blocksize = arg > when '-f' then filename = arg > end > end > -----8<----- > > Regards, > > Tom