If variable equals string help

Hi All,
Trying to get my bash script if statement to work however my if variable equals xxx statement doesnt appear to work, could anyone shed some light.

./script $password &> output
INCORRECTPASS=`grep "Permission denied, please try again." output`
        echo "$INCORRECTPASS"
        if [[ $INCORRECTPASS == "Permission denied, please try again." ]]; then
        echo "Incorrect Password"
fi

As you can see i have put in an echo to print the variable set and this prints sucessfully so I know for sure the variable exists.

Thanks

Would have been wise to post the error msg as well, so we don't have to guess... My guess is, if sees too many words in the first operand. Try quoting the variable.

There isnt an error message, the script completes as if the variable didnt match the if statement. Quoting the variable also doesnt work.

Run it with the shell options -v and -x set and post the output.

Hi RudiC as requested.

#!/bin/bash
clear
+ clear
echo -e "\033[1;94m";
+ echo -e '\033[1;94m'
echo "Checking input file"
+ echo 'Checking input file'
Checking input file
if grep -nv '^44[0-9]\{10\}$' numberlist.txt
        then
                echo -e "\033[1;31m";
                echo 'Please check the above entries in the numberlist.txt file.'
                echo -e "\033[1;37m";
                exit
fi
+ grep -nv '^44[0-9]\{10\}$' numberlist.txt
sleep 1
+ sleep 1
echo "***************************************************************************************************************"
+ echo '***************************************************************************************************************'
***************************************************************************************************************
echo "The Script is currently in progress, exiting from this window will stop the script and cause it not to complete"
+ echo 'The Script is currently in progress, exiting from this window will stop the script and cause it not to complete'
The Script is currently in progress, exiting from this window will stop the script and cause it not to complete
echo "***************************************************************************************************************"
+ echo '***************************************************************************************************************'
***************************************************************************************************************
VAR=`grep -c "44" numberlist.txt`
grep -c "44" numberlist.txt
++ grep -c 44 numberlist.txt
+ VAR=1
echo "The amount that will be checked is $VAR"
+ echo 'The amount that will be checked is 1'
The amount that will be checked is 1
./msscript $1 &> expectoutput
+ ./msscript random
INCORRECTPASS=`grep "Permission denied, please try again." expectoutput`
grep "Permission denied, please try again." expectoutput
++ grep 'Permission denied, please try again.' expectoutput
' INCORRECTPASS='Permission denied, please try again.
echo "$INCORRECTPASS"
' echo 'Permission denied, please try again.
Permission denied, please try again.
        if [[ "$INCORRECTPASS" == "Permission denied, please try again." ]]; then
        echo "Incorrect Password"
fi
 == \P\e\r\m\i\s\s\i\o\n\ \d\e\n\i\e\d\,\ \p\l\e\a\s\e\ \t\r\y\ \a\g\a\i\n\. ]]
cat expectoutput | tr -d $'\r' | awk '{print}' ORS=', ' | grep -o 'MS ??[^\n]*' | sed 's/\--//g' | sed 's/\Please e//g' | sed 's/\--//g' |  sed 's/;.*//' | sed 's/\MS ??,//g' | sed 's/\ //g' > intialout
+ cat expectoutput
+ tr -d $'\r'
+ awk '{print}' 'ORS=, '
+ grep -o 'MS ??[^\n]*'
+ sed 's/\--//g'
+ sed 's/\Please e//g'
+ sed 's/\--//g'
+ sed 's/;.*//'
+ sed 's/\MS ??,//g'
+ sed 's/\ //g'
echo "CREATING CSV FILE CALLED relay-finaloutputfile.csv"
+ echo 'CREATING CSV FILE CALLED relay-finaloutputfile.csv'
CREATING CSV FILE CALLED relay-finaloutputfile.csv
#rm expectoutput
#rm intialout

Are you sure there's no DOS <CR> line terminator in the grep output?

Sorted it by just using the below however I would still like to understand why it didnt match the pattern.

INCORRECTPASS=`grep -c "Permission denied, please try again." expectoutput`
        if [[ "$INCORRECTPASS" == "1" ]]; then

---------- Post updated at 02:14 PM ---------- Previous update was at 02:11 PM ----------

On looking at the file in Vi this is the line (not sure if the ^M is causing an issue)

Permission denied, please try again.^M

Yes, it is causing the issue - . is not equal to .^M

With your new version you're no longer checking for an exact match to the whole line.

Remove the <CR> (= ^M) char from INCORRECTPASS and your former comparison should fly. (Or add it to the string you compare it to).