title: Loop through a directory, tar each subdirectory to a destination folder
body: <p>I'm trying to loop in the SOURCE directory, tar each subfolder to DEST directory without success.
  I've tested a few variations, but none is acceptable, so I'm looking for some help.
  These are the closest ones.</p>
  <p>Thanks</p>
  <p>Structure:</p>
  <pre><code>/srv/source
      sub1
      sub2
      sub3
  </code></pre>
  <p>I would like to have a tar for each sub as this:</p>
  <pre><code>/srv/dest
      sub1.{DATE}.tar.gz
      sub2.{DATE}.tar.gz
      sub3.{DATE}.tar.gz
  </code></pre>
  <p>These where the tests I made:</p>
  <pre><code>#!/bin/bash
  
  DATE=$(date '+%Y.%m.%d')
  SOURCE=/srv/source
  DEST=/srv/dest
  
  find ${SOURCE} -maxdepth 1 -mindepth 1 -type d -printf '%f\n' -execdir tar zcvf ${DEST}/{}-${DATE}.tar.gz -C ${DEST}/{} . \;
  
  </code></pre>
  <pre><code>#!/bin/bash
  
  DATE=$(date '+%Y.%m.%d')
  SOURCE=/srv/source
  DEST=/srv/dest
  
  for DIR in &quot;$(find ${SOURCE} -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | xargs -0)&quot;
  do
    tar zcvf ${DEST}/${DIR}-${DATE}.tar.gz -C ${SOURCE}/${DIR} .
  done
  </code></pre>
  <p><strong>EDIT:</strong></p>
  <p>This is working</p>
  <pre><code>for DIR in ${SOURCE}/*
  do
    [ -d &quot;${DIR}&quot; ] &amp;&amp; tar zcf ${DEST}/$(basename &quot;${DIR}&quot;)-${DATE}.tar.gz -C ${SOURCE}/$(basename &quot;${DIR}&quot;) .
  done
  
  </code></pre>