title: Multiple inotify events in one script
body: <p>I'm trying to write a bash script (which is installed as a service) to watch multiple directories and move any files that are created in that directory to another directory. For example, I want to move any files created in /home/test/directory1 to /opt/directory1 but I also want to move any files created in /home/test/directory2 to /opt/directory2 but all in one script as a running service. This is my script so far;</p>
  <pre><code>#/bin/bash
  
  directory=/home/test/directory1
  archive=/home/test/archive
  target=/opt/directory1
  
  inotifywait -m &quot;$directory&quot; --format '%w%f' -e create |
      while read file; do
          cp &quot;$file&quot; &quot;$archive&quot;
          mv &quot;$file&quot; &quot;$target&quot;
      done
  </code></pre>
  <p>Any pointers would be greatly appreciated,
  Thanks.</p>