Hi Guys,
i have a variable which hold a string value of "in" when i try to compare this value against another value the if statement is not working.
$a=in
if [ "$a" == "=" ]
then
echo "Not a Walid match"
else
echo "Walid Match"
fi
Thank You.
tried the way u said ... still its not working error message : binary operator expected
code
if [ $a eq "=" ]; then echo "Not a walid match"; else echo "walid match"; fi
suppose if i change to
if [ $a == "=" ]; then echo "Not a walid match"; else echo "walid match"; fi
it works but the output is "Walid Match" where as my ouput should be "Not a walid Match"
ktrimu
March 31, 2010, 1:45am
4
copy "=" to a variable
$b = "="
pludi
March 31, 2010, 1:47am
5
The red '$' is your problem. Remove it, and it should work. To check for further errors, run (depending on your shell)
ksh -n your.script
bash -n your.script
Also, if you're assigning strings it's always a good idea to put quotes around them.
Moderator,
that was a typo in my script ... the $ is not there in my script ... but still its not working and not giving me the excepted result ... pls help
frans
March 31, 2010, 2:20am
7
Your logic is reversed : you try if $a equal '=' then not valid match
Use '!=' (not equal) or reverse the statements
a=in
if [ "$a" != "=" ]
then
echo "Not a Walid match"
else
echo "Walid Match"
fi
That could also be written
a=in
[ "$a" = "=" ] && echo "Valid Match" || echo "Not a Valid match"
clx
March 31, 2010, 2:24am
8
nitinrp1:
Hi Guys,
i have a variable which hold a string value of "in" when i try to compare this value against another value the if statement is not working.
$a=in
if [ "$a" == "=" ]
then
echo "Not a Walid match"
else
echo "Walid Match"
fi
Thank You.
which shell?
you have value of variable "a" as "in". And you are comparing a with symbol "=" !?
moreover, for true condition, you are echoing not valid!
can you please elaborate with your requirement.
by the way, if all true, please try = instead ==
gaur84
March 31, 2010, 2:25am
9
awk -v a="in" '{if(a=="=") {print hi} else print "bye"}'
Thanks for pointing out the typo .... its working now ...
---------- Post updated at 01:28 AM ---------- Previous update was at 01:25 AM ----------
Sorry for the confusion, there was a typo from my sdie ...