I'm trying to save value from a curl command to a variable in a bash script.
Script looks like this
#!/bin/bash
curr=$(pwd)
IP_addr="192.168.0.102"
username="root"
password="pass"
HTTP_STATUS=$(curl -IL --silent $username:$password@$IP_addr | grep HTTP)
echo
echo "echo the variable works!"
echo $HTTP_STATUS
isOK=$(echo $HTTP_STATUS)
status="HTTP/1.1 401 Unauthorized"
echo
if [[ $HTTP_STATUS == $status ]]; then
    echo "The same the same!"
else
    echo "$isOK is not the same as $status"
fi
echo
if [ "$status" == "$isOK" ]
then
    echo "The same the same!"
else
    echo "$isOK is not the same as $status"
fi
I am deliberately passing the wrong password in order for curl to return HTTP/1.1 401 Unauthorized. I want a function to check if wrong credentials are sent to a server.
The strange thing is that when I save the output from the curl command ie
HTTP_STATUS=$(curl -IL --silent $username:$password@$IP_addr | grep HTTP | tee $curr/test.txt)
To a file with tee I get this printed in file HTTP/1.1 401 Unauthorized. But if I remove the tee command ie
HTTP_STATUS=$(curl -IL --silent $username:$password@$IP_addr | grep HTTP)
And execute the script I get following print in terminal
./test.sh 
echo the variable works!
HTTP/1.1 401 Unauthorized
is not the same as HTTP/1.1 401 Unauthorized
is not the same as HTTP/1.1 401 Unauthorized
I tried with following as well but same result
HTTP_STATUS=`curl -IL --silent $username:$password@$IP_addr | grep HTTP`
The variable HTTP_STATUS seems to be blank when I do the checks in the if statements. How is this possible and why is the output of the command saved to a file with tee and echo the variable works but not when using the variable in the if statements?
Best regards

$status, then ending with a (possibly empty) sequence of characters.