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.