Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Using “watch” [1] to run your program is a bad idea. The watch command executes a program at regular intervals, by default it runs once every second.

What you should use instead is “inotifywait” [2] to execute your program(s) whenever there is a change. This way the program will run, for example, every time you save your changes. There are many utilities that make use of inotify (the library that powers inotifywait) some of them are fsnotify [3], fswatch [4] and watchexec [5].

[1] https://linux.die.net/man/1/watch

[2] https://linux.die.net/man/1/inotifywait

[3] https://github.com/fsnotify/fsnotify (written in Go — golang)

[4] https://github.com/emcrisostomo/fswatch (written in C++)

[5] https://github.com/watchexec/watchexec (written in Rust)



If you like inotify, you might also like entr [1].

I only found out about it few days ago, but it seems nice so far.

[1]: http://eradman.com/entrproject/


Wow this is amazing. You made my day with this tool!


If you're going to be using any system like this (either watch or inotifywait), be careful. It's a good chance it's going to run in an "intermediate" state when it's not supposed to run and can do harm to your system (delete files or whatever). Bash scripts are especially dangerous, but it applies to any language.

A good idea would be to at least run the script in some kind of sandbox, so you don't accidentally do something dumb.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: