Why does env -S with quoted strings in the shebang line work fine in Ubuntu but not in macOS?
9
votes
1
answer
1829
views
I have the following script in an executable file
test-shebang.mjs
and I wanted to use zx
to run my script but have my ~/.zshrc
be sourced before that:
#!/usr/bin/env -S zsh -c 'source ~/.zshrc; zx --install $@' --
console.log("work pls")
./test-shebang.mjs
works fine in Ubuntu:
❯ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/ "
SUPPORT_URL="https://help.ubuntu.com/ "
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/ "
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy "
UBUNTU_CODENAME=jammy
❯ zsh --version
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
But when I copy over the same script in macOS, I get this error:
❯ ./test-shebang.mjs
zsh:1: unmatched '
❯ zsh --version
zsh 5.9 (x86_64-apple-darwin23.0)
❯ sw_vers
ProductName: macOS
ProductVersion: 14.4
BuildVersion: 23E214
Why does this happen?
I tried with bash
as well but running into errors there as well. FWIW, I'm doing this roundabout way of doing things because I've installed zx
via pnpm
which itself is installed via brew
and I would prefer not to set PATH
which would just make the script longer.
Asked by runofthemillgeek
(193 rep)
Apr 8, 2024, 05:06 PM
Last activity: Apr 8, 2024, 09:06 PM
Last activity: Apr 8, 2024, 09:06 PM