csh script help
Hi everyone!
I am writing a new shell mf.s which acts as the commandline parser which does the following. ex commandline: mf.s -c *.c -f right tempfile -r 2 3 4 it will select the option given at the command line and do the appropriate job. there r three options to select from -f -r and -c and any other option given at command line is illegal option. So if the command line has -f it will run a script findtext.s(written by me) and if the option is -r, it will run the script right.s and if the given option is -c it will run the script count.s. let me tell you about the option -c.this will rin the script count.s which has the wc command in it.So if we pass a -c *.c option to it ,it should select each file and display the no of words char and lines in it. My problem is ,when should I stop running the count and handle a different option. *.c pass a bunch of files as arguments .So I execute a while loop to handle the files.But when will the *.c end to handle the next option. So,I gave a if statement like this: if ( $argv[$n] == '-[a-z]' ) break I want to break out of the while if the next argument is an option and not a .c file . I want that if statement to handle an option i.e if it is a flag like string and just come out of the loop.is my if statement correct? will it chech whether an argument is a string which contains an option like -r or -f or any alphabet after a '-'. I am also posting the while statement for you to see. I need a reply urgently.Please reply.Thankyou. while ( $n <= $#argv ) switch ( $argv[$n] ) case '-f': @ arg1 = $n + 2 @ n++ ./findtext.s $argv[$n] $argv[$arg1] @ n = $n + 2 breaksw case '-r': @ sec = $n + 2 @ trd = $n + 3 @ n++ ./right.s $argv[$n] $argv[$sec] $argv[$trd] @ n = $n + 3 breaksw case '-c': @ n++ while ( $n <= $#argv ) if ( $argv[$n] == '-[a-z]' ) break ./count.s $argv[$n] @ n = $n + 1 end breaksw default: echo Illegal option @ n++ endsw end |
first off, I'd use getopt instead of trying to parse your way through the argv's yourself. That will make your life a lot easier. If you do that, then the your options will look something like so:
Code:
set argv = ( `/usr/bin/getopt c:vr: $*` ) |
Thanks
Thank you,Brian.UR answer gave me a lot of knowledge and solved my problem.I was working on it for 3 long days.
Sorry for posting my question in that way.I got exhausted at the end of the day and I posted it in a hurry.Thanks again. |
All times are GMT -5. The time now is 06:16 AM. |