A. Lau A. Lau -4 years ago 200
Linux Question

Multiple shebangs to work for different OS

Is there a way I can have multiple shebangs?

So I can call

#!/usr/bin/env python3
on Ubuntu, but MacOS doesn't seem to have an equivalent, and I would like to call
#!/usr/bin/python3
instead on it.

So is it possible to do something like:

#!/usr/bin/env python3
#!/usr/bin/python3

Answer Source

We can't have multiple shebang lines - there can only be one and it should always be the first line.

If you need to support multiple versions of Python based on OS, it is best to write a small shell wrapper that invokes your python script with the right interpreter, probably with an exec.

MacOS does have /usr/bin/env.


See this post:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download