title: Making a bash script to update/download github tools
body: <p>I can't get the following script to work like this:
  There is a file named githubrepos.txt with urls for example "<a href="https://github.com/GDSSecurity/Windows-Exploit-Suggester" rel="nofollow noreferrer">https://github.com/GDSSecurity/Windows-Exploit-Suggester</a>". The scripts checks if the folder already exists in /opt/ last part of the given url.</p>
  
  <p>The script breaks on the part where it should check if the folder even exists. It always goes to the else part even if it exists. I think it hase something to do with the if [ -d $localdir ] part. Probably with the $localdir variable. I spend hours on it and cant get it to be fixed. Would like some help, its my first script written.</p>
  
  <pre><code>#!/bin/bash    
  #Start downloading github repos
  for repos in $(cat githubrepos.txt)
  do
    localrepodir="/opt/${repos##*/}"
    echo $localrepodir
    if [ -d $localrepodir ];
      then
      echo ${repos##*/}
      echo "Already exists, updating tool with git pull";
      cd $(echo $localrepodir | tr -d '\r');
      git pull
      else
      echo ${repos##*/}
      echo "Tool needs to be cloned";
      git clone $repos
    fi
  done
  </code></pre>