Lua shebang compatible with DOS newlines

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Lua shebang compatible with DOS newlines

Egor Skriptunoff-2

Sometimes we need a shared Lua script to be run and edited from both Linux and Windows.
The problem is the CR character in a shebang line is treated by Linux as usual magic-less character.
After newlines in a Lua script were converted from LF to CRLF, the recommended Lua shebang
#!/usr/bin/env lua
would be treated as the non-working one
#!/usr/bin/env lua@
I have replaced here non-printable character "\r" with printable "@" just to make it visible.

The following shebang can successfully survive DOS newlines:
#!/usr/local/bin/lua -e--
#!/usr/local/bin/lua -e--@
because both "--" and "--\r" are correct Lua programs.
Sadly, this shebang depends on the Lua interpreter path on your system.

How to make CRLF-compatible shebang invoking "/usr/bin/env"?
Recently it was impossible, but starting with Debian 10 the "env" utility has been given the ability to pass arguments on a shebang line with the "-S" option.
Now we can use the following CRLF-compatible Lua shebang:
#!/usr/bin/env -S lua -e--

Hope this information was helpful for Lua users working with Windows.