emcrisostomo / fswatch

A cross-platform file change monitor with multiple backends: Apple OS X File System Events, *BSD kqueue, Solaris/Illumos File Events Notification, Linux inotify, Microsoft Windows and a stat()-based backend.
https://emcrisostomo.github.io/fswatch/
GNU General Public License v3.0
4.96k stars 327 forks source link

beginner question about exit/breaking out of fswatch #285

Closed molleweide closed 2 years ago

molleweide commented 2 years ago

Hi there,

why doesn't this exit the command

   launch_do() {
    local TITLE="wm_custom_launcher"

    open -n -a "/Applications/Alacritty.app" \
        --args -t "${TITLE}" \
        -e "launcher-filter" "${TITLE}" # -e launch_filter
    local ect=0
    fswatch -0 /tmp/$TITLE | while read -d "" event
      do \
        ect=$(( $ect + 1 ))
        echo "e$ect: ${event}"
        if test "$ect" = "2"; then
            # it turns out my value is always written on second event.
            local rt=$(cat "/tmp/${TITLE}")
            echo "rt: $rt"
            # break
            exit
        fi
    done

    echo "outside..."
}

I spawn a new terminal instance and writes it's results to a tmp file. rt echoes correctly but it doesn't break or exit? What am I doing wrong?

molleweide commented 2 years ago

oh never mind. I just found this thread solving my problem.

https://unix.stackexchange.com/questions/336894/kill-the-parent-of-a-child-pipe-process