Source command in bash script

1.4k Views Asked by At

I am trying to put a source command in a bash script so that I can quickly set up and use a virtual environment when writing django websites.

I tried the following without much success as my path was not prefixed with the (path) like it does when I simply enter it at the prompt.

#!/bin/bash
current=$(pwd | cut -d'/' -f5)
source ~/Documents/virtual-env/$current/bin/activate

Can anybody help and let me know what I am overlooking?

EDIT:

pwd is "example" and the source is:
"~/Documents/virtual-env/example/bin/activate".

After some research I think I need to use something like:
"source ./script"

(not working) as I think the environment is created but not esculated to its parent enviroment which I believe is not possible now.

1

There are 1 best solutions below

0
On
#!/bin/bash
current=$(basename $(pwd))
source ~/Documents/virtual-env/$current/bin/activate
exec bash # Run new interactive shell in the new environment

But I recommend to try virtualenvwarpper instead.