The path of the executable that runs the script may differ across users

I guess once upon a time, I was able to find this information by Googling but not this time.

I believe each script file (e.g. my.py, run.sh, etc) could have the path to an executable that is supposed to parse & run the script file. For example, a bash script file run.sh could start with:

#!/bin/bash

Then, my user will run it like:

$ ./run.sh

What if some users may not have bash there but has one under /usr/sbin/? Actually, my issue is Python3. Some users may have python3 not as /usr/bin/python3. Some distros seem to install it as /usr/bin/python37 while some other /usr/bin/python. Yet again, some do $HOME/bin/virtualenv/python3.

At least, what could I do to tell any (future) user’s shell that my script should be run by which python. Or, even better if I could tell “Try which python3, and if not available, try which python.”

Answer

In the computer world, this first line that starts with #! is called Shebang.

There’s no global agreement. Each family of OS applies in their own way. The unique trusted solution is defining what OS you want to apply, configure according them and testing it.

Here, a good article if you want to go deeper with this concept: Shebang (Unix)

Leave a Reply

Your email address will not be published. Required fields are marked *