I recently tried to automate the setup of an Ubuntu VM with a bash script (I am new to bash scripting).
The issue is that the way I set it up, it doesn't work. Particularly the mkvirtualenv and workon commands don't work in the bash script. How do I create a virtualenv in a bash script with passing it a variable and then install into the virtualenv via pip?
#!/bin/bash
VENV_NAME='name_of_virtualenv'
#Setting up virtualenv
mkdir --mode=770 /var/virtualenvs
chown -R www-data:www-edit /var/virtualenvs
chmod 771 /var/virtualenvs
echo '# virtualenv and virtualwrapper' >> ~/.bashrc
echo ' export VIRTUALENV_USE_DISTRIBUTE=1' >> ~/.bashrc # <-- Always use pip/distribute
echo ' export WORKON_HOME=/var/virtualenvs' >> ~/.bashrc
echo ' source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bashrc
echo ' export PIP_VIRTUALENV_BASE=$WORKON_HOME' >> ~/.bashrc
echo ' export PIP_RESPECT_VIRTUALENV=true' >> ~/.bashrc
source ~/.bashrc
mkvirtualenv --distribute '{VENV_NAME}'
workon {VENV_NAME}
pip install psycopg2
pip install --upgrade PIL