Question: I am trying to compare output of a command with a string. 

```
# echo "$status"
Stateretired
# if [ "$status" == "Stateretired" ] ; then echo "Instance down"; else echo "Well nah"; fi
Well nah
#

```

### Update:

Tried with single `=` but same results.

```
# echo "$status"
Stateretired

# if [ $status = "Stateretired" ] ; then  echo "Instance retired"; else  echo "Well nah"; fi
Well nah

```

### Debug trace

With debug I saw a strange thing with comparison `'[' Stateretired == 'Stateretired' ']'`. Is it normal ? Hope its not. 

```
++ grep State
++ sed -E 's/ +//g ; s/\|//g'
+ status='Stateretired'
+ echo 'Stateretired'
Stateretired
+ mystatus=Stateretired
+ '[' Stateretired == 'Stateretired' ']'
+ echo 'Instance not down'
Instance not down

```

### color coding

In keep on debugging, I came to know that the color coding is causing this problem. 

```
echo "$status" | tr -d '[:cntrl:]'
State[31mretired[0m

```

I am trying to find a way to remove them.

Answer: 
As you found yourself, the control characters are making the strings different.  

You can try to remove the control characters. Another approach is skipping them:

```
status="State[control characters]retired[more control characters]"
if [[ "${status}" =~ State.*retired ]]; then
   echo "Instance down"
else
   echo "Well nah"
fi

```

This solution will fail when the status can contain values like `State is not retired` or `Previous State was retired, now back to work`.
You should use = instead of ==

This should work!

```
# echo "$status"
Stateretired
# if [ "$status" = "Stateretired" ] ; then echo "Instance down"; else echo "Well nah"; fi
#

```