|
|
|
|
|
by deathanatos
107 days ago
|
|
> I'd give this a try, works with any language: #!/usr/bin/env -S "/path/with spaces/my interpreter" --flag1 --flag2
This won't do what you're thinking it does. If I run that, I get: env: No terminating quote for string: /path/with"/path/with
… because the string you've given env -S on my system is malformed, and lacks a terminating quote. (You can test this w/ just giving an unterminated quoted string to env … I have no idea why the messaging is so funky looking, but that's sort of par for the course here.)As I alluded to in my post, shebangs don't handle escaping. Now, yes, you're thinking that env will do it, here. The other problem with shebangs is that they're ridiculously unstandardized. On Linux, for example, that shebang will parse out to: #!/usr/bin/env -S "/path/with spaces/my interpreter" --flag1 --flag2
argv[0]: "/usr/bin/env"
argv[1]: "-S"
argv[2]: "\"/path/with spaces/my interpreter\" --flag1 --flag2"
argv[3]: <script filename>
& then -S proceeds as you expect it to. Things appear to work.On my system, #!/usr/bin/env -S "/path/with spaces/my interpreter" --flag1 --flag2
argv[0]: "/usr/bin/env"
argv[1]: "-S"
argv[2]: "\"/path/with"
argv[3]: "spaces/my"
argv[4]: "interpreter"
argv[5]: "--flag1"
argv[6]: "--flag2"
argv[7]: <script filename>
This is because Linux passes everything after the first space as a single arg. macOS splits on spaces, but does no further processing (such as some form of backslash escapes) beyond that.Since, env -S '"/path/with' <other args…>
is nonsense, env errors out with the above error. |
|