Hallo Ricardo, Am 02.11.2017 um 22:31 schrieb Ricardo Wurmus: > This made me wonder if we could avoid shell wrappers in more cases.
This is an interesting challenge :-) > If > the target script is a Python script we could set the environment > variables right after the Python shebang with Python code. If the > target script is a shell script we can set environment variables right > there after the shebang. Basically thsi would be a good solution IMO. But I'm afraid it might be complicated to insert the code "right after the […] shebang". For example Python has "doc-strings" [1], this is: if the first statement of the script is a string (expression statement), this string is put into the variable __doc__. So for at least for Python we might need a language-aware scanner to insert the code at the correct position. We might need similar tor other languages. But taking your challenge :-) I had another idea which should work for all script languages: The real script's she-bang delegates to the wrapper (instead of /bin/sh), which execs "interpreter $0". Here is a proof on concept: ....8<------- real.py #!/tmp/wrapper.sh print("This is real") import sys, os print("sys.path[:2]", sys.path[:2]) print("argumentes:", sys.argv) print("ppid", os.getppid()) ....8<------- ....8<------- wrapper.sh #!/bin/sh echo "This is the wrapper" echo "arguments in wrapper:" "$@" echo "ppid:" $PPID export PYTHONPATH=/foo/bar exec python3 /tmp/real.py "${@:2}" # <- replace first argument by full path ....8<------- I have to admit that this still adds another script and is less elegant, but should be easier to implement. []1] https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring -- Regards Hartmut Goebel | Hartmut Goebel | h.goe...@crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible |