Parse parameters with getopts


 
Thread Tools Search this Thread
Top Forums Programming Parse parameters with getopts
# 1  
Old 03-29-2010
Parse parameters with getopts

Hi, this is my problem

I have script with two parameters -n name and -s surname. Both have arguments and I want to know how parse these parameters with getopts. When you write

./names -n John -s White
it find you all persons, which name is John White, but when you write

./names -n John
it will find you all Johns in database. Similar when you write

./names -s White
it will find all person who have White in their surname.

What is more ./names -n John -s White must be equal to ./names -s White -n John



Is it possible?
# 2  
Old 03-29-2010
Possible? Yes. But I'd suggest you post again in the homework forum. And don't forget the special rules that apply there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getopts with optional parameters

Hi Unix Gurus, i am on learning path of unix, and yet to discover many things. I came across with this requirement where i need to pass parameters but the position of parameters is not fixed so after doing some google search got to know "getopts" can handle that. So here is my code: function... (3 Replies)
Discussion started by: gnnsprapa
3 Replies

2. Shell Programming and Scripting

Order of getopts parameters

Hi, Does the order of argument and non-argument command line parameters matter to getopts? with a getopts line in my script of getopts p:cs opt a command line of <script> -p 5 -s only picks up the -p option, while <script> -s -p 5 picks up both. Removing the space between the p and the... (3 Replies)
Discussion started by: rojomoke
3 Replies

3. Shell Programming and Scripting

[Solved] I need to parse an username in parameters

Hi! Thank you ina advance for your Help. Sorry my english, Im from Argentina! Great Place!!! So, here si my problem I have a variable, lets say PARAMETERS that could be set like this: PARAMETROS="-Usistemas string1 -Astring2 -G -Y -Kcoco -Y string4 -Z" or PARAMETROS="string1... (1 Reply)
Discussion started by: Hercraft
1 Replies

4. Shell Programming and Scripting

using getopts to parse a command line

i have the following scenario want to run the following script with manadory and optional argumnets Manadory options are : filename="" port="" optional arguments type -t balances -b bal prices -p ./test filename port -t A -b bal my code i have that won't parse the options is... (1 Reply)
Discussion started by: nano2
1 Replies

5. Shell Programming and Scripting

Parse HTML tag parameters and text

Hi! I have a bunch of HTML files, which I want to parse to CSV files. Every page has a table in it, and I need to parse each row into a csv record. With awk and sed, I managed to put every table row in separate lines. So my file looks like this: <TR> .... </TR> <TR> .... </TR> ...One... (1 Reply)
Discussion started by: senszey
1 Replies

6. AIX

tuning network parameters : parameters not persist after reboot

Hello, On Aix 5.2, we changed the parameters tcp_keepinit, tcp_keepintvl and tcp_keepidle with the no command. tunrestore -R is present in inittab in the directory /etc/tunables we can clearly see the inclusion of parameters during reboot, including the file lastboot.log ... (0 Replies)
Discussion started by: dantares
0 Replies

7. Shell Programming and Scripting

using getopts

Hi, I have a program where I want to use getopts. I want to use "-i" option and then optionally supply arguments. If user dosent supply arguments, then also it should work. Please tell me how to proceed. Here is some code, this is not right code btw but a sample to understand what I want to... (1 Reply)
Discussion started by: som.nitk
1 Replies

8. Shell Programming and Scripting

parse long input parameters

anybody know a nice way to parse long input parameters such as --path /dir1/dir2/ (see below). Now I have more than 10 input parameters and it's confusing having parameters like -q something, I would prefer longer ones case $OPTKEY in --path) M_PATH=$OPTARG ;; -s) ... (3 Replies)
Discussion started by: larne
3 Replies

9. Shell Programming and Scripting

getopts help

Hi i have part of the scripts below ,getopt for -h or ? not working for me. can anybody tell me if this sytax right or wrong. #!/usr/bin/ksh program=$(basename $0) ##################################################################################### function usageerr { RC=1 ... (3 Replies)
Discussion started by: GrepMe
3 Replies

10. Shell Programming and Scripting

getopts takes options for parameters

Here is my post with a question about getopts. I am running korn shell on Solaris 5.8. I am trying to ensure that certain options require a parameter, which is easy enough. I have found that if multiple options are entered on the command line together, but the parameter for one of the options is... (1 Reply)
Discussion started by: UCD-Randy
1 Replies
Login or Register to Ask a Question