Strange bug with xsel and khotkeys

I’m having a strange issue running a script that uses xsel.

I reported it here, and @ngraham explained that since KHotKeys is no longer supported, from a KDE perspective there isn’t a bug here to figure out, and suggested I ask here to see if anyone could advise.

If I make a bash script like this:

xsel -b > /tmp/xsel.txt 2>&1
touch /tmp/got_here

…if I run that from the CLI, it works fine: /tmp/xsel.txt shows up, and /tmp/got_here show up, as expected.

But if I run that instead using a hotkey that I have mapped to the executable script, I see /tmp/xsel.txt, but /tmp/got_here never appears. There are no errors or unexpected content in /tmp/xsel.txt.

If I use xclip instead of xsel, it works fine. This implies to me that xsel is crashing after it has finished writing the file?

Can anyone advise a way to run the script in a equivalent way to how KHotKeys runs it, so I can reproduce the xsel issue from the CLI? That would help me report it to whoever maintains xsel.