title: Basename puts single quotes around variable
body: <p>I am writing a simple shell script to make automated backups, and I am trying to use basename to create a list of directories and them parse this list to get the first and the last directory from the list.</p>
  
  <p>The problem is: when I use basename in the terminal, all goes fine and it gives me the list exactly as I want it. For example:</p>
  
  <pre><code>basename -a /var/*/ 
  </code></pre>
  
  <p>gives me a list of all the directories inside /var without the / in the end of the name, one per line.
  BUT, when I use it inside a script and pass a variable to basename, it puts single quotes around the variable:</p>
  
  <pre><code>while read line; do
  dir_name=$(echo $line)
  basename -a $dir_name/*/ &gt; dir_list.tmp
  done &lt; file_with_list.txt
  </code></pre>
  
  <p>When running with +x:</p>
  
  <pre><code>+ basename -a '/Volumes/OUTROS/backup/test/*/'
  </code></pre>
  
  <p>and, therefore, the result is not what I need.</p>
  
  <p>Now, I know there must be a thousand ways to go around the basename problem, but then I'd learn nothing, right? ;)</p>
  
  <p>How to get rid of the single quotes?
  And if my directory name has spaces in it?</p>