Comparing two variables

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 1
Reputation: rajip23 is an unknown quantity at this point 
Solved Threads: 0
rajip23 rajip23 is offline Offline
Newbie Poster

Comparing two variables

 
0
  #1
Apr 11th, 2008
Comparing two variables

--------------------------------------------------------------------------------

Script
#!/bin/sh
hardware=PC
os=WindowsNET
for i in `cat newservers`
do
x=`sudo /opt/openv/netbackup/bin/admincmd/bpplclients |grep $i |head -40 |grep $i|awk '{print $3;exit}'`
if [ "$i" -eq "$x" ]
then
echo "$i is already added"
else
echo "Need to add"
fi
done


O/p in debug mode

bash-2.05$ sh -x server_test.sh
hardware=PC
os=WindowsNET
+ cat newservers
+ sudo /opt/openv/netbackup/bin/admincmd/bpplclients
+ grep ds01smspsbby
+ head -40
+ awk {print $3;exit}
+ grep sun
x=sun
+ [ sun -eq sun]
sun is already added


+ sudo /opt/openv/netbackup/bin/admincmd/bpplclients
+ grep pluto
+ head -40
+ awk {print $3;exit}
+ grep pluto
x=
pluto is already added

for both conditions its showing the same output.Can soomeone correct this script?


Thanks,
Rajeswari
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 25
Reputation: blater is an unknown quantity at this point 
Solved Threads: 7
blater's Avatar
blater blater is offline Offline
Light Poster

Re: Comparing two variables

 
0
  #2
Apr 11th, 2008
The line
if [ "$i" -eq "$x" ]

should be
if [ "$i" = "$x" ]

The -eq operator is used for numeric comparisons, "=" is used for string comparisons.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC