title: bash tar error doesn't create tar.gz
body: <p>I have the following bash script:</p>
  
  <pre><code>#DIR is something like: /home/foo/foobar/test/ without any whitespace but can also include whitespace
  DIR="$( cd "$( dirname "$0" )" &amp;&amp; pwd )"
  #backup_name is read from a file
  backup_name=FOOBAR
  date=`date +%Y%m%d_%H%M_%S`
  #subdirs is also read from the same file
  subdirs=etc/ sbin/ bin/
  filename="$DIR/Backup_$backup_name"_"$date.tar.gz"
  
  cd /
  echo "filename: $filename"
  echo "subdirs $subdirs"
  cmd='tar czvf "'$filename'" '$subdirs
  echo "cmd tar: $cmd"
  $cmd
  </code></pre>
  
  <p>But I get following output:</p>
  
  <pre><code>filename: /home/foo/foobar/test/Backup_FOOBAR_20120322_1529_35.tar.gz
  subdirs: etc/ sbin/ bin/
  cmd tar: tar cfvz "/home/foo/foobar/test/Backup_FOOBAR_20120322_1529_35.tar.gz" etc/ sbin/ bin/
  etc/
  # ... list of files in etc
  # but no files from sbin or bin directory
  tar: "/home/foo/foobar/test/Backup_FOOBAR_20120322_1529_35.tar.gz": can open not execute: File or directory not found
  tar: not recoverable error: abortion.
  </code></pre>
  
  <p>However, when I copy the echo output of the tar command, make a cd to / and paste it into the bash shell it is working: </p>
  
  <pre><code>tar cfvz "/home/foo/foobar/test/Backup_FOOBAR_20120322_1529_35.tar.gz" etc/ sbin/ bin/
  etc/
  </code></pre>
  
  <ul>
  <li>Every variable is defined and there is no trailing newline</li>
  <li>I also tried $cmd with backticks</li>
  <li>the two variables: backup_name and subdirs are read from a file (I did not include the reading process in the code)</li>
  </ul>
  
  <p><strong>edit:</strong> I just copied my script to a dir with no whitespace and changed the line:</p>
  
  <pre><code>cmd='tar czvf "'$filename'" '$subdirs
  #to
  cmd="tar czvf $filename $subdirs"
  </code></pre>
  
  <p>and it's working now but when I do the same in a dir which also contents whitespaces I get still the same error.</p>
  
  <p><strong>edit2:</strong> reading from file (the file is read before anything else happens) </p>
  
  <pre><code>config="config.txt"
  local line
  while read line
  do
      #points to next free element and declares it
      config_lines[${#config_lines[@]}]=$line
  done &lt;$config
  backup_name=${config_line[0]}
  subdirs=${config_line[1]}
  </code></pre>
  
  <p>What is wrong with my bash script?</p>