title: Getting a 'source: not found' error when using source in a bash script
body: <p>I'm trying to write (what I thought would be) a simple bash script that will:</p>
  
  <ol>
  <li>run virtualenv to create a new environment at $1</li>
  <li>activate the virtual environment</li>
  <li>do some more stuff (install django, add django-admin.py to the virtualenv's path, etc.)</li>
  </ol>
  
  <p>Step 1 works quite well, but I can't seem to activate the virtualenv. For those not familiar with virtualenv, it creates an <code>activate</code> file that activates the virtual environment. From the CLI, you run it using <code>source</code></p>
  
  <pre><code>source $env_name/bin/activate
  </code></pre>
  
  <p>Where $env_name, obviously, is the name of the dir that the virtual env is installed in.</p>
  
  <p>In my script, after creating the virtual environment, I store the path to the activate script like this:</p>
  
  <pre><code>activate="`pwd`/$ENV_NAME/bin/activate"
  </code></pre>
  
  <p>But when I call <code>source "$activate"</code>, I get this:</p>
  
  <pre><code>/home/clawlor/bin/scripts/djangoenv: 20: source: not found
  </code></pre>
  
  <p>I know that <code>$activate</code> contains the correct path to the activate script, in fact I even test that a file is there before I call <code>source</code>. But <code>source</code> itself can't seem to find it. I've also tried running all of the steps manually in the CLI, where everything works fine.</p>
  
  <p>In my research I found <a href="http://www.doughellmann.com/articles/CompletelyDifferent-2008-05-virtualenvwrapper/Listing1.html" rel="noreferrer">this script</a>, which is similar to what I want but is also doing a lot of other things that I don't need, like storing all of the virtual environments in a ~/.virtualenv directory (or whatever is in $WORKON_HOME). But it seems to me that he is creating the path to <code>activate</code>, and calling <code>source "$activate"</code> in basically the same way I am.</p>
  
  <p>Here is the script in it's entirety:</p>
  
  <pre><code>#!/bin/sh
  
  PYTHON_PATH=~/bin/python-2.6.1/bin/python
  
  if [ $# = 1 ]
  then
      ENV_NAME="$1"
      virtualenv -p $PYTHON_PATH --no-site-packages $ENV_NAME
      activate="`pwd`/$ENV_NAME/bin/activate"
  
      if [ ! -f "$activate" ]
      then
          echo "ERROR: activate not found at $activate"
          return 1
      fi
  
      source "$activate"
  else
      echo 'Usage: djangoenv ENV_NAME'
  fi
  </code></pre>
  
  <p>DISCLAIMER: My bash script-fu is pretty weak. I'm fairly comfortable at the CLI, but there may well be some extremely stupid reason this isn't working.</p>