0

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?

Priya
  • 173
  • 6
  • 18
  • 5
    in the first line you overwrite your `PATH` variable so subsequent calls can't find python – Nullman May 02 '22 at 11:10
  • 1
    @fourjr no it doesn't. The error is due to the fact OP is overriding the `PATH` variable – Aserre May 02 '22 at 11:17
  • There are a bunch of all-caps variable names with special meanings, so it's best to use lower- or mixed-case names to avoid conflict (unless you *do* want one of those special meanings). See [this answer](https://stackoverflow.com/questions/673055/correct-bash-and-shell-script-variable-capitalization/673940#673940) – Gordon Davisson May 02 '22 at 16:28

1 Answers1

2

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"
teambob
  • 1,994
  • 14
  • 19