Pages: Welcome | Projects

she-bang max length

2017/3/14
Tags: [ Hacking ] [ GNU/Linux ] [ shell ]

An interesting problem rose today at work. We make use of virtual environment (virtualenv) for Python, and it turns out to have difficulties with long prefixes.

The problem turned out to be related with the maximum length of a #! line inside scripts, which essentially boils down to the handling of the executable bit from the kernel side.

Shell scripting in a rather difficult environment, with baroque syntax for baroque semantics, compatibility problems and whatsoever. The bash hackers wiki is an extremely useful resource. I found this page which pointed me at a nice list of #! limitations.

In a regular system you never have this kind of issues. The interpreter is probably in /usr/bin, and you never reach that length. In our case this is fairly likely to happen. A good solution is calling python directly, with /path/to/python -m module or with /path/to/python module.py, instead of relying on the #!/path/to/python she-bang.