In a script , i would like to check if the argument ( $1, $2 inside the script) contain wildcard (*,? etc). how do i do it?
> script_name arg1 arg*
$1 (arg1) does not contain wildcard, but $2 (arg* )contains wildcard. how can i tell in script?
i need to do this is because :
if arg1... (3 Replies)
How do I check if the argument passed to a script is an integer?
I am writting a script that will take to integers and want to be able to check before I go on.
I am using bourne shell.
Thanks in advance (13 Replies)
I have a script that when called can have 1 or 2 command arguments. If only 1 command argument is passed into the script how can I check that the second argument is null? I am working in Korn shell in a UNIX environment.
Example of script call with 2 arguments:
% statreport 0300 1430
... (6 Replies)
I am passing a string as argument. Need to check if it contains "-".
If it contains "-" then check if it contains "-r" .If Yes then print some message else check if it contains "-t".If yes print some message. How this check can be done using shell script?
How I can do this by using IF OR... (7 Replies)
Can someone please help me with this SHELL script?
I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1.
Here is a start but I have no clue how to... (3 Replies)
If ($argv == “-debug”) then
Echo “in loop”
Endif
But this is not working. If I modify this code and remove “-“, then it works.
Similarly I am getting problem using grep command also
Grep “-debug” Filename
Can someone please help me on how to resolve these... (1 Reply)
I want to make a script that check for the argument passed to it and generates an error in case any character/string argument passed to it.
I am using below code, but its not working. can anyone help.
#!/bin/bash
if ]; then
echo 'An integer argument is passed to the script hence... (3 Replies)
Hi guys,
I have created a csh script which allows user to pass input argument with the script like:
cluster_on_lev3.csh -t <value> -p <value>
Example:
cluster_on_lev3.csh -t 2.3 -p 0.05
Now I want to create an error code where if user passes input argument without spaces , the code... (16 Replies)
I need a script that should print 'yes' if the argument is a valid shell variable name else 'No' if it is not a valid shell variable. A valid one begins with an alphabet or percentage (%) character and is followed by zero or more alphanumberic or percentage (%) characters.
For example:
$... (6 Replies)
Discussion started by: pingiliarjun
6 Replies
LEARN ABOUT POSIX
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