Bash string comparison false for some reason (but works in screen)

I’ve been making a docker container for JRiver Media Center. I had to do some hackery to prevent the window from being minimizeable and other Option Windows popping up behind the Main window and leaving you in a state where you cannot do anything.

This works fine when I’m executing the script with screen, but does not work without it.

You can find the container here

Anyways, the script in question is witch is called that because I pipe the output of xprop -root -spy into it.

The script being

while read line; do
    echo "[$(date +%d-%m-%Y_%H-%M-%S)] Received: $line" >> /tmp/xpropspy.log
    search=$(echo "$line" | grep "_NET_ACTIVE_WINDOW(WINDOW): window id # ")

    echo "[$(date +%d-%m-%Y_%H-%M-%S)] Search: $search" >> /tmp/xpropspy.log

    if [ ! -z "$search" ]; then
        hex=$(echo "$line" | cut -c41-)
        echo "[$(date +%d-%m-%Y_%H-%M-%S)] Hex: $hex" >> /tmp/xpropspy.log
        clients=$(obxprop --root | grep '^_NET_CLIENT_LIST(WINDOW)' | grep -o '[0-9]\+')

        echo "$clients" >> /tmp/xpropspy.log

        if [ "$hex" == "0x0" ]; then
            echo "Entering 0x0 if..."  >> /tmp/xpropspy.log
            switch_to=$(echo $clients | awk '{print $NF}')
            echo "[$(date +%d-%m-%Y_%H-%M-%S)] Changing Window to: $switch_to" >> /tmp/xpropspy.log
            wmctrl -i -a $switch_to
            echo "False '$hex' != '0x0'" >> /tmp/xpropspy.log

Now to the logging when minimizing a window this logs

[21-07-2019_17-43-28] Received: _NET_ACTIVE_WINDOW(WINDOW): window id # 0x0
[21-07-2019_17-43-28] Search: _NET_ACTIVE_WINDOW(WINDOW): window id # 0x0
[21-07-2019_17-43-28] Hex: 0x0
False '0x0' != '0x0'

Currently, I have no idea why this possibly would evaluate to false and even less idea why this works when running the script with screen. The working code is in the master branch. The currently failing one in the dev branch.

And the reason I want to change this is, simply because screen exits instantly. So right now screen -l is called so often that it does use quite a lot more cpu than this should use (because s6-overlay assumes the service is dead, then runs the run script… again… and again and so forth). I could add a sleep or something like that, but I’d rather just get rid of screen entierly.

I did another check of how I called the two scripts


screen -S xpropspy -dm bash -c "xprop -root -spy | /etc/services.d/xpropspy/"


exec xprop -root -spy | /etc/services.d/xpropspy/

I did not specify bash, adding the #!/bin/bash to the top of the xpropspy script fixed this…

Whyever 0x0 is not 0x0 in sh I have no idea… but whatever. Let’s just not use it anymore.

Looks like you are supposed to use just = in sh instead.