0

I am trying to create a @reboot entry in in a cron file to run a bash script to initialise a python virtual environment and following that run my python programs. Before I can do that I need to be able to do this from a bash script. My knowledge of scripting is not great, however, you have to soldier on.

I create the environment for my python programs on a day to day basis by navigating to my project folder and typing.

cd ~/project_folder
pipenv shell

The shell is running and within it I can invoke my python scripts from the cli. In trying to automate this I tried the following in a .sh file.

#! /usr/bin/bash
cd ~/project_file
pipenv shell 

When I ran the .sh script it worked, however any cli code I try following the 'pipenv shell' line is not run because the bash script is waiting for the environment to drop. But if the environment drops I can't run the python scripts.

There is more that I am aiming to do with the scripting but this is the first hurdle I am having difficulty getting over. Sadly, I have been on this all day and so I am now shouting out for a leg up. If anyone could point me in the right direction I would be much obliged.

  • Every script runs in a separate process. When that process exits, any environment changes made in that process are lost; the parent process does not change. This is a common beginner FAQ. – tripleee Mar 30 '22 at 18:23
  • Duplicate of https://stackoverflow.com/questions/12351702/how-to-write-a-bash-script-to-set-global-environment-variable and/or https://stackoverflow.com/questions/1464253/global-environment-variables-in-a-shell-script – tripleee Mar 30 '22 at 18:24
  • Also for the problem you are apparently trying to solve, https://stackoverflow.com/questions/67284203/run-pipenv-shell-as-part-of-a-bash-script – tripleee Mar 30 '22 at 18:26
  • I think that ..203 has an answer I can use. Thank you tripleee. – David Poundall Mar 30 '22 at 18:44
  • Does this answer your question? [How to write a bash script to set global environment variable?](https://stackoverflow.com/questions/12351702/how-to-write-a-bash-script-to-set-global-environment-variable) – Faisal Nazik Mar 30 '22 at 20:38
  • Hi Faisal, not directly. It's a great pointer for environment questions, but as it turned out it was more of a 'pipenv' configuration problem in the end. Thank you for the link though - it was a more than interesting read. – David Poundall Mar 31 '22 at 10:16

0 Answers0