title: Extract date (YYYYMMDD) from filename in bash script
body: <p>I am trying to extract a date from a filename. This is what I do:</p>
  
  <pre><code>find ${DPPATH}/${DBNAME}*.dmp.gz ${MTIMECMD} -type f -exec
  </code></pre>
  
  <p>(perform an action. this works as expected.)</p>
  
  <p>What I would like to do, is extract the date (it will be in YYYYMMDD format) from the filename that is being found via the find command, and use that date to pass to the find command, where the action is being performed.</p>
  
  <p>I've tried this to try and grab the date above the find command in the script, hoping to extract:</p>
  
  <pre><code>MOVEDATE=echo ${DPPATH}/${DBNAME}*.dmp.gz ${MTIMECMD} -type f |grep -Eo '[[:digit:]]{8}';
  </code></pre>
  
  <p>Edit, tried this suggestion:</p>
  
  <pre><code>${MOVEDATE}=echo ${DPPATH}/${DBNAME}*.dmp.gz ${MTIMECMD} -type f |grep -Eo '[[:digit:]]{8}'\;
  </code></pre>
  
  <p>Results was:</p>
  
  <pre><code>=echo: not found
  </code></pre>
  
  <p>Then, pass $MOVEDATE to the find command with no luck.</p>
  
  <p>I am using the 'debug' option in the script (<code>-x</code>), and the result is:</p>
  
  <pre><code>&lt;filename&gt;  cannot execute [Permission denied]
  </code></pre>
  
  <p>The filename will named like this:</p>
  
  <pre><code>blah_blah_blah_exp_01_20180221_0100.dmp.gz:
  </code></pre>
  
  <p>The MTIMECMD from above is just a variable that looks for a file older than x amount of hours.</p>
  
  <p>Any tips would be greatly appreciated.</p>