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 [email protected] | 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 [email protected] | 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.
echo $STATE
(without quotes) will turn any run of blank characters into a single space. Example:foo=$'a:\tb'; echo $foo; [ "$foo" != "a: b" ] && echo no match
$(...)
and theSTATE
var at all.if gnome-extensions show [email protected] | grep -q '^State:[[:blank:]]*ENABLED$'; then ...; fi
.echo $STATE
will NOT tell you ifSTATE
isState: ENABLED
orState:<10 Spaces Here>ENABLED
orState:<TabCharacter>ENABLED
of which only the first will match.gnome-extensions show [email protected] | grep State | hexdump -C
to your question, maybe someone else will explain it to you better ;-)