4 ms·
https://en.wikipedia.org/wiki/Shebang_(Unix)#Argument_splitting https://en.wikipedia.org/wiki/Shebang_(Unix)#Argument_splitt...
by Hello71 1y ago
https://en.wikipedia.org/wiki/Shebang_(Unix)#Argument_splitting https://en.wikipedia.org/wiki/Shebang_(Unix)#Argument_splitt...
- alkh 1y agoThanks, but the main question is how come the behaviour is still the same whether you pass the flag or not? I would get it if it just failed without "-S" but it works as intended. I am wondering if this is cause I might not be using the GNU version of env, so this is less relevant? Edit: looks to be the version thing indeed, this doesn't work for someone on Ubuntu
- fc417fc802 1y agoAt some point coreutils added -S in order to support the behavior of BSD and MacOS. I would guess that whatever implementation you're using then added -S as a noop in order to (at long last) permit the portable usage of multi-argument shebang lines. Until both of those things happened there was no portable way to pass multiple arguments in a shebang. You used to have to do really stupid things (ex https://unix.stackexchange.com/a/399698 https://unix.stackexchange.com/a/399698). https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#g_t_002dS_002f_002d_002dsplit_002dstring-usage-in-scripts https://www.gnu.org/software/coreutils/manual/html_node/env-...
- alkh 1y agoActually, you might be onto something! If I test with explicit quoting in terminal, BSD and GNU produce the same behavior:(`env 'bash -c "echo hello"'` fails while `env -S 'bash -c "echo hello"'`) works. I wasn't aware of this: "To test env -S on the command line, use single quotes for the -S string to emulate a single parameter. Single quotes are not needed when using env -S in a shebang line on the first line of a script (the operating system already treats it as one argument)"(from your second link). This is different for shebang on Mac though: GNU env works with or without '-S': #!/opt/homebrew/bin/genv -S bash -v echo "hello world!" BSD env works with or without '-S' too: #!/usr/bin/env -S bash -v echo "hello world!" To conclude, looks like adding `-S` is the safest option for comparability sake :).