I am making a bash script for Linux which closes the terminal window if the window loses focus.
On the command line, I was able to do this:
termwin=$(xdotool getactivewindow) while : do if [[ $(xdotool getactivewindow) != $termwin ]] then exit fi done
It works typed manually into a terminal, but, if I put it into a script, instead of closing the window when focus is lost, the script simply stops. No error or anything, just back to a prompt.
I feel like I'm missing something basic.
After reading this...: See here
I tried running this as ". test.sh" rather than "./test.sh" and it worked. The link describes the difference in these methods as running the script as a subprocess or as part of the main process, respectively. Can anyone just explain this, and/or modify the script to run successfully with "./" instead of ". ", in the latter creates issues?