title: linux zip and exclude dir via bash/shell script
body: <p>I am trying to write a bash/shell script to zip up a specific folder and ignore certain sub-dirs in that folder.</p>
  
  <p>This is the folder I am trying to zip "<strong>sync_test5</strong>":</p>
  
  <p><img src="https://i.stack.imgur.com/JkROy.png" alt="enter image description here"></p>
  
  <p>My bash script generates an ignore list (<a href="https://superuser.com/a/312302/220765">based on</a>) and calls the zip function like this:</p>
  
  <pre><code>#!/bin/bash
  
  SYNC_WEB_ROOT_BASE_DIR="/home/www-data/public_html"
  SYNC_WEB_ROOT_BACKUP_DIR="sync_test5"
  SYNC_WEB_ROOT_IGNORE_DIR="dir_to_ignore dir2_to_ignore"
  
  ignorelist=""
  if [ "$SYNC_WEB_ROOT_IGNORE_DIR" != "" ];
  then
      for ignoredir in $SYNC_WEB_ROOT_IGNORE_DIR
      do
          ignorelist="$ignorelist $SYNC_WEB_ROOT_BACKUP_DIR/$ignoredir/**\*"
      done
  fi
  
  FILE="$SYNC_BACKUP_DIR/$DATETIMENOW.website.zip"
  cd $SYNC_WEB_ROOT_BASE_DIR;
  zip -r $FILE $SYNC_WEB_ROOT_BACKUP_DIR -x $ignorelist &gt;/dev/null
  echo "Done"
  </code></pre>
  
  <p>Now this script runs without error, however it is <strong><em>not</em></strong> ignoring/excluding the dirs I've specified.</p>
  
  <p>So, I had the shell script output the command it tried to run, which was:</p>
  
  <pre><code>zip -r 12-08-2014_072810.website.zip sync_test5 -x  sync_test5/dir_to_ignore/**\* sync_test5/dir2_to_ignore/**\*
  </code></pre>
  
  <p>Now If I run the above command directly in putty like this, it works:</p>
  
  <p><img src="https://i.stack.imgur.com/jS19V.png" alt="enter image description here"></p>
  
  <p>So, why doesn't my shell script exclude working as intended? the command that is being executed is identical (in shell and putty directly).</p>