Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

At 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://www.gnu.org/software/coreutils/manual/html_node/env-...



Actually, 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 :).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: