I wrote a fairly simple script here that is designed to display a text information dialog box with zenityand continuously read data from a remote TCP connection and display it in a dialog box. This works ... However, I would like the whole script to end if I close the dialog zenity.
Is there any way to do this? I don’t think I can check anything in the while loop, because the script can be stopped while reading data from a remote TCP connection.
#!/bin/bash
on_exit() {
zenity --display=:0 --error --text="Script has exited." &
}
while getopts "a:p:t:" OPTION; do case "$OPTION" in
a) address="$OPTARG";;
p) port="$OPTARG";;
t) title="$OPTARG";;
esac; done
exec &> >(zenity --display=:0 --text-info --title=$title || exit)
trap "on_exit" EXIT
while read data < /dev/tcp/$address/$port; do
echo $data
done
Note. . This will be launched on IGEL Linux. I have no way to install additional packages. So, ideally, the solution I'm looking for is native to Bash.
Update
exec. @BachLien .
PID=$$
exec &> >(zenity --display=:0 --text-info --title=$title; kill $PID)