title: parse result of `ls -l` with bash script
body: <p>I need to store the name of every file contained in a directory with a bash script and processes it in some way:</p>
  
  <pre><code>drwxrwxr-x  5 matteorr matteorr  4096 Jan 10 17:37 Cluster
  drwxr-xr-x  2 matteorr matteorr  4096 Jan 19 10:43 Desktop
  drwxrwxr-x  9 matteorr matteorr  4096 Jan 20 10:01 Developer
  drwxr-xr-x 11 matteorr matteorr  4096 Dec 20 13:55 Documents
  drwxr-xr-x  2 matteorr matteorr 12288 Jan 20 13:44 Downloads
  drwx------ 11 matteorr matteorr  4096 Jan 20 14:01 Dropbox
  drwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 Music
  drwxr-xr-x  2 matteorr matteorr  4096 Jan 19 22:12 Pictures
  drwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 Public
  drwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 Templates
  drwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 Videos
  </code></pre>
  
  <p>with the following command I'm able to split the result of <code>ls -l</code> in between all the spaces and then access the last element, which contains the name:</p>
  
  <pre><code>ls -l | awk '{split($0,array," ")} END{print array[9]}'
  </code></pre>
  
  <p>However it returns only the last line (i.e. <code>Videos</code>) so I need to iterate it over all the lines returned by the <code>ls -l</code> command.</p>
  
  <ul>
  <li>how can I do this?</li>
  <li>Is there a better way to approach this whole problem?</li>
  </ul>
  
  <p><strong>ADDED PART</strong></p>
  
  <p>To be a little more specific on what I need to do:</p>
  
  <p>For all the files contained in a directory if it is a file I won't do anything, if it is a directory I should append the name of the directory to all the files it contains.</p>
  
  <p>So supposing the directory Videos has the files:</p>
  
  <pre><code>-rwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 video1.mpeg
  -rwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 Video2.wmv
  </code></pre>
  
  <p>I need to rename them as follows:</p>
  
  <pre><code>-rwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 video1_Videos.mpeg
  -rwxr-xr-x  2 matteorr matteorr  4096 Oct 18 18:43 Video2_Videos.wmv
  </code></pre>