title: I want to watch a directory for changes,if new file is arrives and send a mail with the filename
body: <p>I created a bash script to check the directory for new file changes and send the mail to recipient.
  But i am getting the error.</p>
  
  <p>I created a bash script,but it is throwing the below error.</p>
  
  <p>script6.sh: line 10: syntax error near unexpected token <code>done'
  script6.sh: line 10:</code>done'</p>
  
  <p>Just i want to know where i am wrong.
  whether the total script is wrong or there any minor error.
  Need help on this.</p>
  
  <pre><code>#!/bin/bash
  targetDir="/somedir"
  while true; do
   files=("$targetDir"/*)
  sleep 1m ## wait 1 minute
  files1=("$targetDir"/*)
  if [[ ${#files[@]} != ${#files1[@]} ]]; then
   mailx -s "New files arrived:$files1" some@mail.com &lt; "$files1"
  fi
  done
  </code></pre>
  
  <p>My tasks are as follows.
  1.observe a directory for incoming files.
  2.If any new file arrives check with the existing files
  3.If it is a new file send a mail to recipient
  I want all the above should be achieve through bash script.</p>