title: How to activate a python virtualenv using a bash script and keep it after the script finishing?
body: <p>I've created a new python venv as usual: <code>python -m venv .venv</code></p>
  
  <p>I need to create a bash script which can activate this venv and keep that state after finishing.</p>
  
  <p>I know, that a normal solution to activate a venv is calling <code>source .venv/bin/activate</code> from terminal or using it via an alias.</p>
  
  <p>But I need this feature in my bash script which does a lot of other useful things for my development.</p>
  
  <p>I tried to do it in a simple way:</p>
  
  <p>my-script.sh:</p>
  
  <pre><code>#!/bin/bash
  
  source ".venv/bin/activate"
  echo $VIRTUAL_ENV
  </code></pre>
  
  <p>When the script is running, the venv is activated, I check it via $VIRTUAL_ENV.
  But after finishing, the state is lost:</p>
  
  <pre><code>max@mbp t3 $ ./my-script.sh
  /Users/max/t3/.venv
  max@mbp t3 $ echo $VIRTUAL_ENV
  
  max@mbp t3 $
  </code></pre>
  
  <p>Is it possible to keep an activated venv after finishing the script?</p>
  
  <p>I need it for my script <code>p</code> which has a lot off different helping commands for python, pip, twine, etc.</p>
  
  <p>I want to be able to do such a thing vith my script <code>p</code> and venv:</p>
  
  <p><code>$ p v</code></p>
  
  <p>1) If there is already activated venv, do nothing</p>
  
  <p>2) If there is a .venv folder, activate the venv and return ACTIVATED venv bash prompt. </p>
  
  <p>3) If there is no .venv folder, first create venv and next activate it. And also return ACTIVATED venv bash prompt.</p>