title: Renaming files in Shell Script Linux
body: <p>I want to rename files I have downloaded from the following script:</p>
  
  <pre><code>exec &lt; input_list.txt
  while read line
  do
  get $line
  wget ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/$2/$4
  # Rename $4
  mv $4 $1"_"$3".bam"
  done
  </code></pre>
  
  <p>The input file (input_list.txt) is tab delimited and contains four columns. The first, $1= name, $2= wget address, $3= factor and $4 is the file name.</p>
  
  <pre><code>A549    wgEncodeBroadHistone    H2azDex100nm    wgEncodeBroadHistoneA549H2azDex100nmAlnRep1.bam
  </code></pre>
  
  <p>I want to rename $4 (the file that has been downloaded) to a shorter file name that only includes the corresponding $1 and $3 terms. For example, <code>wgEncodeBroadHistoneA549H2azDex100nmAlnRep1.bam</code>
   becomes <code>A549_H2azDex100nm.bam</code></p>
  
  <p>I've played around with <code>"</code> but I keep getting error messages for the mv command and that <code>$4</code> is a bad variable name. Any suggestions would be greatly appreciated. </p>