04-24-2008
problem, with if condition in function
Hi All,
I have a function which reads parameter and gets the value from config file.
The entry in the file can be either of two
Name=value or
Name[variant]=value
so if the variant is not present it should return me the generic value ie Name without variant.
I am first searching for variant in the file and taking the count using grep, so if it is > 0 then search for variant else generic.
But if condition is not evaluating properly and is always treating it as 0.
Below is the function.................Please HELP ME.............
______________________________________________________________
function getProp () {
name=$1;variant=$2
var=$(grep -c \b"$variant"\b "$RUNNING_CONFIG_FILE")
if [ $var -eq 0 ];then
{
awk -F '([ \t]=)|(=)' '
BEGIN {
value=""
exitcode=0
}
/^[ \t]*#/ {next}
$1 ~ /'$1'$/{value=$2;exitcode=0}
END {print value}' "$RUNNING_CONFIG_FILE"
}
else
{
awk -F '([ \t]*=)|(=)' '
BEGIN {
value=""
OFS="="
exitcode=0
}
/^[ \t]*#/ {next}
/'$name'\['$variant'\]/ || /'$name'\[[ ]'$variant'[ ]\]/ { if (NF == 3) {value=$2"="$3} else {value=$2}}
END {if ("'"$3"'" ~ /NoSpace/) {gsub("(^[ \t]*)|([ \t]*$)","",value);print value} else {print value}}' "$RUNNING_CONFIG_FILE"
}
fi
}
______________________________________________________________
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi, :)
pls consider the following if statement
if //g') ]
then
........
else
.......
when i execute the script i am getting the following error
'(' unexpected
I am not able to find the mistake.
could anybody tell where i did mistake.
cheers
RRK (13 Replies)
Discussion started by: ravi raj kumar
13 Replies
2. Shell Programming and Scripting
hi,
actully i need the belp for the below.
host_list=" Host1 host2 host3 host4 "
n=`hostname`
i need to put the condition like the below
if n is among the host mention in the host_list if
then
#some stugg
else
# some other stuff
fi (1 Reply)
Discussion started by: mail2sant
1 Replies
3. Shell Programming and Scripting
Hi,
I'm currently writing a bash script, that starts multiple threads:
____________________
#!/bin/bash
loop=0
while((loop!=10))
do
thread &
((loop++))
done
#wait for all sub-processes (thread) to finish
wait
___________________
Now I want to know, what happens, if a... (2 Replies)
Discussion started by: tho99
2 Replies
4. Shell Programming and Scripting
Hi ,
I am trying the following simple script . But it is always giving 1 output. Dont know why
#!/bin/sh
find . -name "a.log"
if ; then
echo "1"
else
echo "0"
fi
Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
Discussion started by: himvat
26 Replies
5. Programming
Hi,
I have written a program in C and have to test the return value of the functions. So the normal way of doin this wud b
int rc
rc=myfunction(input);
if(rc=TRUE){
}
else{
}
But instead of doing this I have called the function in the if() condition. Does this have any... (2 Replies)
Discussion started by: sidmania
2 Replies
6. Shell Programming and Scripting
Hi, I'm writing a bash script and i have a condition that goes
if
then
break
fi
but, when i go to run it, i come across this
line 10: '
where line 10 is the if
I don't know what's going on :( (2 Replies)
Discussion started by: channyboy
2 Replies
7. Shell Programming and Scripting
Hi All,
I'm a newbie here, I'm just wondering how can i disable my 1st sed command if there's no file found on Yes_Directory and process instead the No_Directory because there's a file found on it.
Yes_Directory="/home/yes/
No_Directory="home/no/
script:
if ; then
sed -i... (8 Replies)
Discussion started by: nikki1200
8 Replies
8. Shell Programming and Scripting
Hello,
How can i put a function into a condition ?
g1 is my function
I tested this in vain
if g1 $1 $2 $3 -ne 0 ];thenif ;then
Thanks for yours suggestions (18 Replies)
Discussion started by: amazigh42
18 Replies
9. Shell Programming and Scripting
Hi All,
I am using below if condition to check whether null is passed as a parameter to the program
if or ;
then
echo "ABC">>$FILE
else
echo "CDF">>$FILE
fi
However it is saying me null=null command not found . Please help me with this (9 Replies)
Discussion started by: Hypesslearner
9 Replies
LEARN ABOUT PHP
variant_int
VARIANT_INT(3) 1 VARIANT_INT(3)
variant_int - Returns the integer portion of a variant
SYNOPSIS
mixed variant_int (mixed $variant)
DESCRIPTION
Gets the integer portion of a variant.
PARAMETERS
o $variant
- The variant.
Note
As with all the variant arithmetic functions, the parameters for this function can be either a PHP native type (integer, string,
floating point, boolean or NULL), or an instance of a COM, VARIANT or DOTNET class. PHP native types will be converted to variants
using the same rules as found in the constructor for the "VARIANT" class. COM and DOTNET objects will have the value of their
default property taken and used as the variant value.
The variant arithmetic functions are wrappers around the similarly named functions in the COM library; for more information on
these functions, consult the MSDN library. The PHP functions are named slightly differently; for example variant_add(3) in PHP cor-
responds to VarAdd() in the MSDN documentation.
RETURN VALUES
If $variant is negative, then the first negative integer greater than or equal to the variant is returned, otherwise returns the integer
portion of the value of $variant.
SEE ALSO
variant_fix(3), variant_round(3), floor(3), ceil(3), round(3).
PHP Documentation Group VARIANT_INT(3)