title: Putting the results of grep & cut in a variable in a bash script
body: <p>I'm new to Stackoverflow and pretty new to bash-scripting as well, so please forgive me for asking such a dork question. I've really browsed trough a lot of answers in here but nothing seems to work for me.</p>
  
  <p>I'm trying to make this little script to check wordpress.org for the latest version, and check if I already have that file on the same directory as where the script is:</p>
  
  <pre><code>#!/bin/bash
  
  function getVersion {
  new=$(curl --head http://wordpress.org/latest.tar.gz | grep Content-Disposition | cut -d '=' -f 2)
  echo "$new"
  }
  
  function checkIfAlreadyExists {
      if [ -e $new ]; then
          echo "File $new does already exist!"
      else
          echo "There is no file named $new in this folder!"
      fi
  }
  
  getVersion
  checkIfAlreadyExists
  </code></pre>
  
  <p>It kind of works as the output is:</p>
  
  <pre><code>jkw@xubuntu32-vb:~/bin$ ./wordpress_check 
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  wordpress-3.4.1.tar.gz
   in this folder! named wordpress-3.4.1.tar.gz
  jkw@xubuntu32-vb:~/bin$ 
  </code></pre>
  
  <p>So I get the right filename with curl&amp;grep&amp;cut but there is something wrong with the variable. When I print it in line 5 it seems allright, but when printed in line 12 it comes out looking funny. Also, the if statement does not work, I do have the file in the same directory.</p>
  
  <p>If I output the result of curl --head <a href="http://wordpress.org/latest.tar.gz" rel="nofollow">http://wordpress.org/latest.tar.gz</a> | grep Content-Disposition | cut -d '=' -f 2 in a textfile, I seem to get a new line in the end, could this be the problem? If I pipe the command to xdd it looks like this:</p>
  
  <pre><code>  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0000000: 776f 7264 7072 6573 732d 332e 342e 312e  wordpress-3.4.1.
  0000010: 7461 722e 677a 0d0a                      tar.gz..
  </code></pre>
  
  <p>..and I can't make any sense of it.</p>
  
  <p>I have tried to pipe the command trough <em>tr '\n' '\0'</em> or <em>tr -d '\n'</em> as suggested in a lot of similiar questions here, but it seems to do nothing. Any ideas?</p>
  
  <p>PS: I'm also wondering where do the lines..</p>
  
  <pre><code>  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
    0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  </code></pre>
  
  <p>..come to my shell output. When I run just the command <em>curl --head <a href="http://wordpress.org/latest.tar.gz" rel="nofollow">http://wordpress.org/latest.tar.gz</a></em> in terminal, the output does not have any lines like this.</p>