1

I have created a virtual environment on my debian system and i made a script that activates it (should).

However when i execute the script nothing shows up, not even an error, my guess is that it is running in a different shell or something but I don't know how to solve it.

Here is the code of the script

#!/bin/bash
source ~/PythonEnv/environments/my_env/bin/activate

I have changed the permissions already with chmod u+x, so that is not a problem.

When i execute the script nothing shows up at all. Any thoughts???

John Dale
  • 51
  • 1
  • 8
  • Add content of ~/PythonEnv/environments/my_env/bin/activate to your question. – Cyrus Dec 31 '19 at 21:20
  • I assume this is a python virtual env? If so, when you `activate` it changes the shell environment and the shell prompt. It doesn't actually run anything. So it is not clear what you are expecting. – kaylum Dec 31 '19 at 21:20
  • @kaylum Yeah you are right, i guess i wanted to make a script that changes the shell environment, is there any way to do that? – John Dale Dec 31 '19 at 21:25
  • Don't know what you mean. If you are talking about the python virtual env feature then `activate` already does the "changes the shell environment". – kaylum Dec 31 '19 at 21:26
  • @kaylum i wanted to make a script that changes the shell environment – John Dale Dec 31 '19 at 21:27
  • Set the variables in any shell file (e.g. `export MY_VAR="my_val"`) and then just `source` that file. – kaylum Dec 31 '19 at 21:40

2 Answers2

1

Add set -x at the beginning of your bash script will do the trick.

-x  Print commands and their arguments as they are executed.

You can see more bash options here http://linuxcommand.org/lc3_man_pages/seth.html

Oded BD
  • 2,788
  • 27
  • 30
0

Adding x-permissions is not necessary, since you are using source with an absolute path. Of course this sets the environment only which is executed by the shell script which you have posted here. If you want the changes in your interactive shell, it is pointless to do it inside a script. You have to source the activate script in your shell (respectively inside that process where you want the environment to be modified).

user1934428
  • 19,864
  • 7
  • 42
  • 87