I’d like to use Bash to run a test suite automatically when I save any file in a given directory.
Is there a mechanism for bash to execute a given script on save events?
Thanks.
::EDIT::
I should have mentioned that I’m on using OSX.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edited: you (the OP) mentioned you use OSX. I’m not aware of any similar tools on OSX. There is a low-level system call (inherited from BSD) called “kqueue“, but you’d have to implement your own user-level tool. There is a sample application from Apple, called “Watcher“, but it’s proof of concept only, and doesn’t do what you want.
There is another thread about this on Stack Overflow (also inconclusive).
For lack of an appropriate tool, if you’re using a specific programming language, I’d advise you to look for solutions already written for it. Otherwise, I think you’re stuck to polling and managing the changes yourself…
Here’s my original, Linux-based answer, for archival purposes:
If you’re using Linux, you might want to take a look at inotify . More specifically, you can install inotify-tools, which include
inotifywait.With it, you can monitor files and directories for a number of events, such as access, modification, opening, closing and many others.
inotifywaitcan exit once the specified event has been detected, and so a simple loop would get you what you want:By the way, many programming languages and environments already have their own continuous test runners (for instance, with Python you could use tdaemon, among others).