We have a script that looks something like this:
#!/usr/bin/env node --unhandled-rejections=strict
console.log("Hi!");
This has been working fine on my laptop (OSX) but when we run it on Linux it just hangs. Using strace we can see it's continuously loading libc and performing
execve("./foo.sh", ["./foo.sh"], ["YARN_VERSION=1.22.4", "HOSTNAME=307d861c7c1a", "PWD=/", "HOME=/root", "NODE_VERSION=12.18.1", "TERM=xterm", "SHLVL=1", "PATH=/usr/local/sbin:/usr/local/"..., "_=/usr/bin/strace", "node --unhandled-rejections=stri"...]) = 0
We can see here that the argument to env is being interpreted as an environment variable. We also know that "node --unhandled-rejections=strict" is passed in as a single argument.
We can see the difference in OSX by creating two scripts. b1.sh:
args=("$@")
echo \"${args[0]}\" \"${args[1]}\" \"${args[2]}\"
and b2.sh
#!/usr/bin/env /tmp/b1.sh foo=bar
When we run b2.sh on OSX we get
"foo=bar" "./b2.sh" ""
on Linux it also hangs.
So it's apparent that arguments are passed to env differently in Linux vs. OSX. In OSX "/tmp/b1.sh" and "foo=bar" are seperate arguments. Where as in Linux they are passed as the same argument.
But why does this cause env to exec the same code over and over again?