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 | 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.


STATE="$(gnome-extensions show | grep State)"
echo $STATE     # output: State: ENABLED


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

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 *