I'm trying to compare two variables inside an if condition:
#!/bin/bash
Jump="/home/Lists/srv"
S=`echo "$1" | perl -ne 'print lc'`
J1=`grep $S $Jump |awk '{print $1}'`
grep $S $Jump >> /dev/null
if [ $? = 0 ]
then
if [ "$S" == "$J1" ]
then
echo "$S" is equal to "$J1" :
ssh -qt $S "$2"
else
echo "$S" is not equal to "$J1"
ssh -qt $J1 "ssh -qt $S $2"
fi
else
ssh -qt $S "$2"
fi
Whenever I try to execute it always goes to else condition. and executes echo "$S" is not equal to "$J1"
I'm executing this script as ./test.sh followed by a server name for ex:
./test.sh hostname1
It should then lower the case and put it in variable S, and search for $S in the file Jump="/home/Lists/srv". If it finds there it should grep the first column and put it in another variable J1. Now, if value of S and J1 are similar, then it should ssh to $S else (1st) it should first ssh to $J1 and then ssh to $S. Else (2nd) if it doesn't find $S in Jump file it should directly ssh $S.
While I'm executing it directly goes to 1st else condition. even if $S and $J1 are similar.
helloandhiare not equal. Also see unix.stackexchange.com/questions/72039/…