I am attempting to call python within a bash script, but the script cannot find it. I have not done bash script programming for over 30 years, so I am not currently adept at bash script debugging. I am using pyenv to select the version of python to use within a particular directory. Here is the setup I am using:
dnessett@homelserv:~/SaltSource/scripts$ ls python_on_root.sh dnessett@homelserv:~/SaltSource/scripts$ cat python_on_root.sh #!/bin/bash sudo python "$@" dnessett@homelserv:~/SaltSource/scripts$ pyenv local 3.10.15 dnessett@homelserv:~/SaltSource/scripts$ python --version Python 3.10.15 dnessett@homelserv:~/SaltSource/scripts$ ./python_on_root.sh sudo: python: command not found
Since I am using sudo within the script to call python, here is the entry in /etc/sudoers that I had hoped would allow sudo to execute the local python interpreter:
#add python to sudo list dnessett homelserv=(root)NOPASSWD:/home/dnessett/.pyenv/versions/3.10.15/bin/python
dnessett is the username and homelserv is the machine name. The pathname following NOPASSWD is where the python version 3.10.15 is located.
The whole point of this is to use the python_on_root.sh script as the interpreter for a Eclipse/PyDev project (see: Stack Overflow thread).
As is apparent from the output given above, sudo cannot find python, even though I have set it as the local python interpreter within ~/SaltSource/scripts. I imagine there is some interaction between the script and sudo that is preventing the latter from finding the intended python interpreter.
Can someone see the problem and advise me how to correct it?