Someone on irc (on channel #kiberpipa at freenode) was trying to solve a bash problem so I decided to challenge myself … here it goes …
Variable MYCOMMAND is of course adjustable to what-ever command you would like to use. Right now it represents the command that is output-ing to stdout word “beje” (semi-random word from my brain) that runs in foreground. Then script enters everlasting while loop that sleeps 1 second, each iteration. Then it saves the output of command combination, find and openssl, which basically means .. sha1 hash of every file in current directory tree. Then on FIRST iteration and on every CHANGE, script tries to kill the previously ran MYCOMMAND if any, after that it executes that command - which means that right now the MYCOMMAND was restarted, after saving few variables for future iteration, loop repeats the process.
Trap is necessary that whathever this script started, stops when user uses ctrl+c key combination. Thanks to this thread.