0

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

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by blater
0

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

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.