Run on file change
entr
run commands when files change
https://eradman.com/entrproject/
inotify & inotifywait
https://linux.die.net/man/7/inotify
https://linux.die.net/man/1/inotifywait
script to run a build script on changes in a directory tree:
#!/bin/bash -eu
DIRECTORY_TO_OBSERVE="js" # might want to change this
function block_for_change {
inotifywait --recursive \
--event modify,move,create,delete \
$DIRECTORY_TO_OBSERVE
}
BUILD_SCRIPT=build.sh # might want to change this too
function build {
bash $BUILD_SCRIPT
}
build
while block_for_change; do
build
done
Doesn't this have a race condition? If you change a file during the build, it won't catch it.
- @FSMaxB yes, it does. If I would save any edits while it was building, I would then save one of the source files again when it was finished to trigger a new build.
– [Dominykas Mostauskis](https://stackoverflow.com/users/1714997/dominykas-mostauskis "7,289 reputation")
- I see that this (my) answer is still being upvoted. I'd like to say that if I had to do this now, I'd use [entr](http://entrproject.org/). See the other answer.
verdere voorbeelden :
https://stackoverflow.com/questions/4060212/how-to-run-a-shell-script-when-a-file-or-directory-changes