My Values are Equal but They are Not

Does anybody understand why this is not being interpreted as true.

Script:

#!/bin/bash

errored=`grep  "errored" new_update_scripts.txt`
echo $errored = "errored"
if [ "$errored" = "errored" ]; then
    echo true
else
    echo false
fi

Output:

[smackey]$ UpdateScripts

errored = errored
false

Is it errored or "errored" in the "new_update_scripts.txt"?

To start with check the value of $errored

$errored has the value 'errored = errored'

and you are checking if $errored == "errored"

which is false

hence you are getting not equal

HTH,
PL

but it's strange...
i copy and paste scottwmackey's script and execute it, the output is
errored = errored
true

It works for me but does fail if I add a space before or after "errored" in the file. Extra text will show up in the output, but the spaces do not. Maybe that's it?

# echo "errored" > new_update_scripts.txt
# ./err.sh
errored = errored
true
#
# echo "errored " > new_update_scripts.txt
# ./err
errored = errored
false
#
# echo " errored" > new_update_scripts.txt
# ./err
errored = errored
false
#
# echo "x errored" > new_update_scripts.txt
# ./err
x errored = errored
false
#

edited to add:
Note that if you put the variable in quotes in the echo line, spaces do show up in the output.

change:
echo $errored = "errored"
to
echo "$errored" = "errored"

# echo " errored" > new_update_scripts.txt
# ./err
 errored = errored
false
#

of course it will false.
cuz grep will print the line of the string which you search...

CMIIW

It was a space. Thanks all for pointing me in the right direction.

You're right in this case because there was an extra space on the line that was picked up by grep, but it should work as long as there are no extra spaces or text. He was echoing the line, which should show anything extra picked up by grep, but it didn't because echo is picky when it comes to unquoted variables.

I learned it the hard way, always use echo "$var" not echo $var