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

The line
if [ "$i" -eq "$x" ]

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

The -eq operator is used for numeric comparisons, "=" is used for string comparisons.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.