Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 264
A. L Avatar asked Jan 04 '23 07:01

A. L


1 Answers

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:

  • Why should the shebang line always be the first line?
like image 136
codeforester Avatar answered Jan 06 '23 21:01

codeforester