Categories
Linux Mastering Development

Compare string containing a colon

I want to create a toggle key for a Gnome extension. An extension keeps up with its state in a property. I chose this extension for example purpose:

gnome-extensions show apps-menu@gnome-shell-extensions.gcampax.github.com | grep State

I was expecting to use the turned value and do a string compare, but I am having problems. The returned value does not seem to be a string.

#!/bin/bash

STATE="$(gnome-extensions show apps-menu@gnome-shell-extensions.gcampax.github.com | grep State)"
echo $STATE     # output: State: ENABLED

COMPARE="State: ENABLED"

# does not work
if [ "$STATE" = "$COMPARE" ]; then
    echo "the state is enabled"
fi

My guess is that the returned result is not a string and that the colon has an obvious meaning in this, but I can’t figure out how to go about this.

Leave a Reply

Your email address will not be published. Required fields are marked *