Created
June 30, 2022 19:19
-
-
Save sevenissimo/a4a13da82c9561430fb70ff61722f73d to your computer and use it in GitHub Desktop.
Linux Inotify events handling in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #set -x | |
| dir="$(mktemp -d)" | |
| mkfifo "${fifo:=$dir/FIFO}" | |
| inotifywait -m -e create $dir 1>$fifo 2>/dev/null & jobs %% | |
| for i in {1..10}; do | |
| ( sleep 2; touch "$dir/$i" ) & | |
| read event <$fifo | |
| printf '[%(%c)T] %s\n' -1 "$event" | |
| done | |
| wait | |
| echo "All finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment