title: Adding Counter in shell script
body: <p>I have below code in my shell script which will keep on sleeping if it doesn't finds any file. And it sleeps for half an hour but currently I don't have any counter like only execute the below code 20 times and then exit the program if the files are still are not there (means don't do anything after 20 checks and exit the full script).</p>
  
  <p>What's the best way to do this problem? So that I am also aware by looking at the emails that it has tried 20 times.</p>
  
  <p>Hope I am clear enough.</p>
  
  <pre><code>while true; do
    if /home/hadoop/latest/bin/hadoop fs -ls /apps/hdtech/bds/quality-rt/dt=$DATE_YEST_FORMAT2 then
         echo "Files Present" | mailx -s "File Present"  -r admin@host.com admin@host.com
         break
    else
         echo "Sleeping for half an hour" | mailx -s "Time to Sleep Now"  -r admin@host.com admin@host.com
         sleep 1800
    fi
  done
  </code></pre>