projg2 / python-exec

Wrapper for multi-implementation install of Python scripts and executables
BSD 2-Clause "Simplified" License
13 stars 6 forks source link

Script interpreter lines with arguments fail to execute #6

Closed bryank-cs closed 3 years ago

bryank-cs commented 3 years ago

If a script starts with:

!/usr/bin/python3 -O -E -s

Then strace shows it being executed as: execve("/usr/lib/python-exec/python3.8/python3", ["/usr/lib/python-exec/python3.8/p"..., "-O -E -s", "script" ....

So it errors out with: Unknown option: - usage: /usr/lib/python-exec/python3.8/python3 [option] ... [-c cmd | -m mod | file | -] [arg] ... Try `python -h' for more information.

mgorny commented 3 years ago

Not convinced it's a bug. Only shebangs with a single argument are portable, i.e. split on the first space. Everything else may be split into multiple arguments (how?) or interpreted as a single argument with spaces.

bryank-cs commented 3 years ago

Oh, I was unaware of this limitation. Very unfortunate. I found there is a workaround using env, at least on some systems:

!/usr/bin/env -S /usr/bin/python3 -O -E -s

Thanks for letting me know.