title: Find files and tar them with trailing or leading space in their name
body: <p>I have a script, that tries to archive the contents of a directory with <code>tar</code>:</p>
  
  <pre><code>#!/bin/bash
  
  find /root/files -type f -name "1*" -print0 | while read -d $'\0' file
  do
      MYDIRNAME=$(dirname "${file}")
      MYFILENAME=$(basename "${file}")
      MYMODIFYDIR=$(echo "$MYDIRNAME" | sed 's/^\///' | sed 's/\//_/g' | sed 's/\ /_/g')
      MYMODIFYFILENAME=$(echo "$MYFILENAME" | sed 's/\//_/g' | sed 's/\ /_/g')
      GZIP=-9 tar -zcvf /root/"$MYMODIFYDIR"_"$MYMODIFYFILENAME".tar.gz "$file"
  done
  </code></pre>
  
  <p>It does not work with files that have leading or trailing whitespace in their name. The error happens when reaching the file <code>/root/files/tetst\ test\ tgdjd/1\ 5765765\ 565765\</code> (<strong>note</strong> the trailing whitespace in the filename):</p>
  
  <pre><code>tar: /root/files/tetst test tgdjd/1 5765765 565765: Cannot stat: No such file or directory
  tar: Exiting with failure status due to previous errors
  </code></pre>
  
  <p>The error given by tar has the trailing whitespace <em>trimmed</em> from the filename.</p>