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

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.

Leave a Reply