07-09-2009
Remove the ':' from after the 'i' in your list of command line switches.
Its all explained in the man page for getopts
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a script that facillitates NDM (Connect::\Direct) transfer to remote hosts. This script uses getopts to parse through the parameters passed to it and to set appropriate variables based upon what was passed in.
Kickoff="mv $PATH/$FILE1 $PATH/$FILE2"
ndm_shell.ksh -p $Node -s $Source -d... (3 Replies)
Discussion started by: google
3 Replies
2. Shell Programming and Scripting
Hi,
My script will take a input file as a parameter(which is not mandatory) and also an option.
ksh my_script.sh <inputfile>
The option -n I have given is no way related to the input file.
Now the problem here is when i execute the script specifying the input file and the option(the way... (4 Replies)
Discussion started by: chella
4 Replies
3. HP-UX
Is there a restriction on levels of using 'getopts' ? I have several scripts, each of which requires an option as the first parameter .
If I call one prg separately it works fine, but when one prg calls another prg and passes the option on the called prg, then the called prg
seems not to process... (3 Replies)
Discussion started by: vslewis
3 Replies
4. Shell Programming and Scripting
I am having some trouble/questions with getopts that I can't find any solid info on with google
I need it to parse things of the syntax of:
-r # # # -f -c
with as many repeats as possible, and it should catch erroneous commands also, but continue going...
my first question is, -r... (3 Replies)
Discussion started by: TurboArkhan
3 Replies
5. UNIX for Dummies Questions & Answers
Hey, i need help with the use of getopts in shell script.
tried reading a lot online, but found incomplete examples (maybe complete but cudn't make out). PLzz help...explain in deatil plzzz, i am a newbie:confused: (3 Replies)
Discussion started by: SasankaBITS
3 Replies
6. Shell Programming and Scripting
First off, I apologize for my lack of knowledge. I realize my problem will probably seem pretty basic to everyone, but I've been at this for several hours now and I've gotten nowhere. I would contact my professor, but it is too late for that.
Anyway, I'm trying to write a function called... (1 Reply)
Discussion started by: Unknown50862
1 Replies
7. Shell Programming and Scripting
Hi all...
I have been looking on here for the past few days for an answer and Im gonna have to break down and ask.
I just learned about the getopts command last week so have been trying to utilize it in my scripts.
Below, I am trying to set up a case structure for options using getopts.... (1 Reply)
Discussion started by: losingit
1 Replies
8. UNIX for Dummies Questions & Answers
while getopts v OPTION
do
case $OPTION in
v) echo "Hello" ;;
*) exit 1;;
esac
done
Suppose I have script tmp.sh
Whose Signature is tmp.sh <fixed_argument>
When I run the script with tmp.sh -v "file", it echoes a hello but, when I try the other way i.e, tmp.sh... (1 Reply)
Discussion started by: Devendra Hupri
1 Replies
9. Shell Programming and Scripting
Hi All,
I am writing a script to pass the getopts argument to the function which I have. But it as soon as I execute the script, the argument is taking it as blank. I tried using multiple way to check but its not working.
Can someone please let me know what wrong in this code.
function1()... (4 Replies)
Discussion started by: sidh_arth85
4 Replies
10. Shell Programming and Scripting
Hi. Can somebody please show me an example of how to use getopts to assign a variable if it's been passed into the script but to set a default if no value has been passed in? And also how to handle a param with multiple values ... so a sub parse (can I use a function for this?)?
Here's my code... (1 Reply)
Discussion started by: user052009
1 Replies
LEARN ABOUT XFREE86
getopt_long
GETOPTS(3) libbash getopts Library Manual GETOPTS(3)
NAME
getopts -- libbash library for command line parameters parsing
SYNOPSIS
$retval getopt_long <Instructions> <Parameters>
DESCRIPTION
This is a documentation for libbash getopts library, that implements getopt_long function for bash(1). For documentation of bash getopts
function, please see getopts(1) ( getopts(1posix) on some systems).
Here is a table for reference:
getopts(1) (or 1posix on some systems) implemented by bash
getopts(3) implemented by libbash.
getopt(1) implemented by getopt utils (part of util-linux)
getopt_long(1) implemented by libbash and installed to section 1 instead of 3 to prevent collision with C man pages.
getopt(3) implemented by GNU C library.
getopt_long(3) implemented by GNU C library.
I have also seen separate getopt utility which part of util-linux package.
The getopt_long function parses the command line arguments. It uses Instructions as the rules for parsing the Parameters.
The Instructions
A string that specifies rules for parameters parsing. The instructions string is built of a group of independent instructions, separated by
a white space. Each instruction must have the following structure:
-<SingleLetter>|--<MultiLetter>-><VariableName>[:]
This structure contains three parts:
-<SingleLetter>
This is the parameter single-letter sign. For example -h.
--<MultiLetter>
This is the parameter's corresponding multi-letter sign. For example --help.
<VariableName>[:]
This is the name of the variable that will contain the parameter value. For example: HELP.
The Variable name can represent one of two variables types:
Flag variable (not followed by ':')
In this case, it will hold the value 1 if 'on' (i.e. was specified on command line) and will not be defined if 'off'.
Value variable (followed by ':')
In this case, the value it will hold is the string that was given as the next parameter in the Parameters string (Separated by
white-space or '=' ). If input contains more then one instance of the considered command line option, an array of the given
parameters will be set as the value of the variable.
The Parameters
The Parameters are simply the parameters you wish to parse.
RETURN VALUE
This function returns a string that contains a set of variables definitions. In order to define the variables, this string should be given
as a parameter to eval function. This value is returned in the variable $retval.
EXAMPLES
Parse command line parameters looking for the flags -h | --help and -v | --version and for the value -p | --path :
getopt_long '-h|--help->HELP
-v|--version->VERSION
-p|--path->PATH:' $*
eval $retval
In this example, for the parameters --help --path=/usr/ the variables that will be created are:
HELP=1
PATH=/usr/
for the parameters --help --path=/usr --path=/bin the variables that will be created are:
HELP=1
PATH=(/usr /bin)
BUGS
Values must not contain the string `__getopts__'. This string will be parsed as a single white-space.
A value should not start with an already defined multi-letter sign. If such a value exists, it will be treated as the equivalent singe-letter
sign. This bug only accures when using a single-letter sign, or a multi-letter sign that are not followed by a `='.
For example: If we have a script named `foo', and we parse the parameters `-d|--dir:' and `-f|--file:', then
foo -d --file
and
foo --dir --file
will not work
foo --dir=--file
will work.
AUTHORS
Hai Zaar <haizaar@haizaar.com>
Gil Ran <gil@ran4.net>
SEE ALSO
ldbash(1), getopt_long(1), getopts(1), getopt(1), libbash(1), getopt(3), getopt_long(3)
Linux Epoch Linux