title: Bash script, watch folder, execute command
body: <p>I am trying to create a bash script with 2 parameters: </p>
  
  <ul>
  <li><strong>a directory</strong> </li>
  <li><strong>a command</strong>. </li>
  </ul>
  
  <p>I want to watch the directory parameter for changes: when something has been changed the script should execute the command. </p>
  
  <p>I'm running MacOS, not Linux; any pointers or external resources would greatly help as I have see that this is difficult to achieve. Really OI am trying to mimic SASS's watch functionality. </p>
  
  <pre><code>#!/bin/bash
  
  #./watch.sh $PATH $COMMAND
  
  DIR=$1  
  
  ls -l $DIR &gt; $DIR/.begin
  #this does not work
  DIFFERENCE=$(diff .begin .end)
  
  if [ $DIFFERENCE = '\n']; then
      #files are same
  else
      $2
  fi 
  
  ls -l $DIR &gt; $DIR/.end
  </code></pre>