Sponsored Content
Full Discussion: Get Options and Parameters
Top Forums Shell Programming and Scripting Get Options and Parameters Post 302360841 by Scott on Saturday 10th of October 2009 06:54:33 PM
Old 10-10-2009
Hi.

Perhaps you're looking for getopts?
Code:
man getopts

(it's a built-in feature, so search for getopts)

Example
bash code:
  1. while getopts a:bc: ARG; do
  2.   case "$ARG" in
  3.     a) echo Option A with $OPTARG;;
  4.     b) echo Option B;;
  5.     c) echo Option C with $OPTARG;;
  6.   esac
  7. done

Code:
./Test -a argument_a -b -c argument_c
 
Option A with argument_a
Option B
Option C with argument_c

A colon after the a and c (getopts a:bc:) means that the option takes an argument.

If your arguments have more than one word, put the words in quotes.

Code:
./Test -a "argument a" -b -c "argument c"
 
Option A with argument a
Option B
Option C with argument c

 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cp options

Hello again, Is there an option for the cp command to overwrite existing files in the destination directory? Cheers Rob (3 Replies)
Discussion started by: milage
3 Replies

2. UNIX for Dummies Questions & Answers

options

I am just beginning to learn unix and I was wondering if there was a list of all the options somewhere on the net or hidden in the man pages? Also do options always have - and then a letter, or can it be - and a number as well? Thanks! (1 Reply)
Discussion started by: terms5
1 Replies

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

4. Post Here to Contact Site Administrators and Moderators

Advt Options ?

Hi, I was wondering if you accept advertising on your site ? Regards, (1 Reply)
Discussion started by: systemali
1 Replies

5. AIX

no options

Hi All, I have a situation here that's very fun... I have a system with AIX and iPlanet (sunOne) installed, when occurs an unknown event on the network the WebServer shows a thousand of CLOSE_WAIT connections and this number grows and grows until the webserver crashs. I read some documents... (2 Replies)
Discussion started by: nascimento.rp
2 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. Ubuntu

Kernel boot options removed by fault, no boot options

Hello Everyone, First of all, I highly appreciate all Linux forum members and whole Linux community. http://forums.linuxmint.com/images/smilies/icon_wink.gif. I wish you the best for all of you ! I will try to be short and concise: I am using Linux Mint 10 for 2 months on 2 ws, and all went... (3 Replies)
Discussion started by: cdt
3 Replies

8. Shell Programming and Scripting

ksh processing options and parameters

I have a requirement where I need to process both options and parameters. command line call ie xxx.ksh -sid TEST1 -search_str LOCKED user1 user2 ..... I am using the following peice of code but I am usure how I can loop through all my parameters user1, user2, ... Note at the minium... (2 Replies)
Discussion started by: BeefStu
2 Replies
All times are GMT -4. The time now is 10:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy