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

How to let Bash script extends User's PATH?

At command line, my command python3 -u jupterlab notebook works perfectly as python locates at /srv/conda/envs/notebook/bin/python3.

Next, I have a bash script, say /usr/local/share/python3-login, its content is

#!/bin/bash -l
echo $PATH
exec python3 -u "$@"

My problem is when I call the script, I encountered an error where python3 not found /usr/local/share/python3-login: line 3: exec: python3: not found

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

I tried to debug by adding echo $PATH at line 2, and turned out PATH is /opt/conda/condabin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/game, which python3 doesn’t exist

How to let my bash script recognize /srv/conda/envs/notebook/bin/python3?

To add more context, I built a docker image with Ubuntu OS

>Solution :

-l Make bash act as if it had been invoked as a login shell
That means it will loads the various profile files as if you just logged in

Since /srv/conda/envs/notebook/bin does not look as a standard path one would see in an profile file, I suspect you do something more to get this in your $PATH in the first place.

solution 1: simply add whatever you do to get this path in your environment, into the script.

solution 2: simply don’t use the -l argument in your shebang.

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