Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Run python script multiple times inside shell script

I am trying to run the below shell script:

PATH=`python getvar.py path`
PATH_REPO="$PATH/$FOLDER_NAME/"
echo "path repo is $PATH_REPO"
ESP=`python getvar.py esp`
echo "esp is $ESP"
DPLYR=`python getvar.py deployer`
echo "deployer is $DPLYR"
recipients_list=`python getvar.py recipients`
echo "recipient list is $recipients_list"
REMOTE_USER=`python getvar.py remoteuser`
echo "user is $REMOTE_USER"

I am getting the output as:

 path repo is /home/developer/user1
./test.sh: line 14: python: command not found
esp is
./test.sh: line 16: python: command not found
deployer is
./test.sh: line 18: python: command not found
recipient list is
./test.sh: line 21: python: command not found
user is

The python file is executing for only 1st command. If run it individually via terminal, it is giving me output, but not from shells script.
How do I make same python script run multiple time in shell script?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The shell is looking in the PATH environment variable for the python interpreter. PATH is a very special environment variable. In step one you are replacing the PATH environment variable with the output of python getvar.py path

I would do the following:

  1. Do you really want to use the special variable "PATH"?
  2. If so, ensure that python getvar.py path includes the path to the python interpreter
  3. Or save the path to the Python interpreter before you change the PATH variable

I would suggest you change your script as follows:

MYPATH=`python getvar.py path`
PATH_REPO="$MYPATH/$FOLDER_NAME/"
echo "path repo is $PATH_REPO"
ESP=`python getvar.py esp`
echo "esp is $ESP"
DPLYR=`python getvar.py deployer`
echo "deployer is $DPLYR"
recipients_list=`python getvar.py recipients`
echo "recipient list is $recipients_list"
REMOTE_USER=`python getvar.py remoteuser`
echo "user is $REMOTE_USER"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading