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: 
If you know exactly what color sequence to expect, then one option is to simply include it in the string you're comparing to:

```
if [ "$status" == $'State\x1B[31mretired\x1B[0m' ] ; then

```

where `$'...'` is a special quoting notation that supports backslash-escapes like `\n` and `\x*HH*` and so on; see [the *Bash Reference Manual*, §3.1.2.4 "ANSI-C Quoting"](https://www.gnu.org/software/bash/manual/bashref.html#ANSI_002dC-Quoting) for more information.

That said, you might want to check the documentation of the command whose output you're capturing; it might support some options to make the output format more scripting-friendly.
It is simple via:

```
test "a" = "a" && { echo "OK" ; }  || { echo "NO" ; }

```