{"id":1144,"hash":"0abd568a3c3daa1e81da2315058eeb92edfd372ed283b71bc7e0999338508433","pattern":"Getting a &#39;source: not found&#39; error when using source in a bash script","full_message":"I'm trying to write (what I thought would be) a simple bash script that will:\n\nrun virtualenv to create a new environment at $1\nactivate the virtual environment\ndo some more stuff (install django, add django-admin.py to the virtualenv's path, etc.)\n\nStep 1 works quite well, but I can't seem to activate the virtualenv. For those not familiar with virtualenv, it creates an activate file that activates the virtual environment. From the CLI, you run it using source\n\nsource $env_name/bin/activate\n\nWhere $env_name, obviously, is the name of the dir that the virtual env is installed in.\n\nIn my script, after creating the virtual environment, I store the path to the activate script like this:\n\nactivate=\"`pwd`/$ENV_NAME/bin/activate\"\n\nBut when I call source \"$activate\", I get this:\n\n/home/clawlor/bin/scripts/djangoenv: 20: source: not found\n\nI know that $activate contains the correct path to the activate script, in fact I even test that a file is there before I call source. But source itself can't seem to find it. I've also tried running all of the steps manually in the CLI, where everything works fine.\n\nIn my research I found this script, 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 activate, and calling source \"$activate\" in basically the same way I am.\n\nHere is the script in its entirety:\n\n#!/bin/sh\n\nPYTHON_PATH=~/bin/python-2.6.1/bin/python\n\nif [ $# = 1 ]\nthen\n    ENV_NAME=\"$1\"\n    virtualenv -p $PYTHON_PATH --no-site-packages $ENV_NAME\n    activate=\"`pwd`/$ENV_NAME/bin/activate\"\n\n    if [ ! -f \"$activate\" ]\n    then\n        echo \"ERROR: activate not found at $activate\"\n        return 1\n    fi\n\n    source \"$activate\"\nelse\n    echo 'Usage: djangoenv ENV_NAME'\nfi\n\nDISCLAIMER: 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.","ecosystem":"pypi","package_name":"bash","package_version":null,"solution":"If you're writing a bash script, call it by name:\n\n#!/bin/bash\n\n/bin/sh is not guaranteed to be bash. This caused a ton of broken scripts in Ubuntu some years ago (IIRC).\n\nThe source builtin works just fine in bash; but you might as well just use dot like Norman suggested.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/670191/getting-a-source-not-found-error-when-using-source-in-a-bash-script","votes":182,"created_at":"2026-04-19T04:52:25.789660+00:00","updated_at":"2026-04-19T04:52:25.789660+00:00"}