Hello,
I kinda newbie in unix so I would like so help.I know that there is a command that compares two integer numbers test (eg. #$1=0 ).I would like to know if it is possible to compare any number with another (eg. 2.3=0 or 3.7!=0 4.5>2.2).
Thank you in advance. (1 Reply)
Hello, I'm searching for a quick method to read numeric values from a file or a defined variable and identifying the largest number. For instance if the following numbers are in a file or defined to a variable:
09192007 09202007 09182007 09172007 09162007
What "short" method could be used to... (7 Replies)
Hi There!
Apologies if this has been asked previously but I couldn't find the answer I was hoping for.
Basically, all I want to do is compare the OS X version against the version that I require in my script. So I'm retrieving the OS version using defaults read, but how can I compare this... (10 Replies)
Hi!
I've come up with a ksh-script that produces one or more lists of hosts.
At the and of the script, I would like to print only those hosts that exists in all the lists.
Ex.
HOSTS="host1 host2 host3 host11"
HOSTS="host1 host2 host4"
HOSTS="host2 host11"
HOSTS="host2 host5 host6 host7... (1 Reply)
Hi,
I am a noob at shell scripting.
basically I am trying to compare row counts from 8 tables in different databases. I have managed to get the row counts using awk from the spool files for both databases.
now I have 16 variables with me
for database 1 :
$A
$B
$C
$D
$E
$F
$G... (3 Replies)
Im trying to compare two numbers with decimals but its not working as expected.
a=1
b=1.1
if
then echo "equal"
fi
When I do this it says that the numbers are equal. Ultimately Im using -le and -ge in the if statements but I tested with -eq for simplicity.
Any way to make this... (3 Replies)
Hi. I do not know how to compare numbers and need help. In my script I have to figure the MAX, MIN, & Avg. Sales amounts.
Please help me.
In the code, "transaction" is a counter.
#!/bin/bash
clear
transaction=0
sales=0
total=0
while test $sales
... (9 Replies)
ValA=-29344
if ; then
echo "NEGATIVE"
else
echo "POSITIVE"
fi
Can someone please tell me how else they would go about doing the above?
When i do it, i get errors such as: (10 Replies)
For numbers between 0 and 1 the below logic is not working.
Output of above shall be "correct" but its echoing "incorrect".Kindly suggest
a=.1
if
then
echo correct
else echo incorrect
fi
Video tutorial on how to use code tags in The UNIX and Linux Forums. (3 Replies)
Discussion started by: itsvikas
3 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