Be careful when using pipes in shell script
Contents
"|"
pipe operator redirects I/O to a subshell.
Variables in a subshell are not visible outside the block of code in the subshell.
Thus the following code doesn’t work as intended.
|
|
The all_closed variable is modified in the subshell created by pipes. The outside one remains unchanged. And the script will never exit with error code 2 no matter all windows are closed or not.
Fixing this piece of code is easy, just avoid using subshell (pipe).
|
|