3 ms·
It's frustrating this is not the same behavior on macOS: https://unix.stackexchange.com/a/774145 https://unix.stackexchange.com/a/774145
by sangeeth96 2y ago
It's frustrating this is not the same behavior on macOS: https://unix.stackexchange.com/a/774145 https://unix.stackexchange.com/a/774145
- silverwind 2y ago`brew install coreutils` and update your `PATH`.
- sangeeth96 2y agoI'm aware of this package for getting other utilities but: 1. I'm worried about this conflicting/causing other programs to fail if I set it on PATH. 2. This probably doesn't fix the shebang parsing issue I mentioned since it's an OS thing. Let me know if that's not the case.
- andreineculau 2y agoYou've got nothing to worry Been doing it for more than a decade and yet to get in trouble. Not one issue. Doing it consistently for my teams as we decrease cognitive load (developing on macs but targeting unix). Others would confirm https://news.ycombinator.com/item?id=17943202 https://news.ycombinator.com/item?id=17943202 Basically software will either use absolute paths i.e. wants to use your OS version for a dependency like grep, or will use whatever grep is in your $PATH and stick to safe invocations regardless if it's BSD/GNU or if it's version x or y
- sangeeth96 2y agoHmm, I haven’t run this experiment myself but I have in the past faced problems overriding default python/ruby commands in PATH that caused some stuff to fail and had to add some specific overrides for `brew` command, for example. > Basically software will either use absolute paths I’ve personally written scripts that break this assumption (that’s a me problem, I guess) so I am quite sure there’s a lot of scripts at the very least that do this. Nevertheless, you’ve given me something to consider.
- 4ad 2y agoThe PATH is irrelevant, this is about how the kernel parses the shebang. It starts exactly /usr/bin/env with two arguments, not some other env binary you might have in your PATH.
- drzaiusx11 2y agoYou can also brew install the gnu tools package and have both side by side for compatibility (gnu tools are prefixed with 'g', gls, gcat, etc I have a script that toggles the prefix on or off via bash aliases for when I need to run Linux bash scripts on a mac.
- rav 2y agoIt seems to me that macOS has env -S as well, but the shebang parsing is different. The result is that shebang lines using env -S are portable if they don't contain any quotes or other characters. The reason is that, running env -S 'echo a b c' has the same behavior as running env -S 'echo' 'a' 'b' 'c' - so simple command lines like the one with uv are still portable, regardless of whether the OS splits on space (macOS) or not (Linux).
- fjarlq 2y agoThis is true. For example, the following shebang/uv header works on both macOS and Linux: #!/usr/bin/env -S uv --quiet run --script # /// script # requires-python = ">=3.13" # dependencies = [ # "python-dateutil", # ] # /// # # [python script that needs dateutil]
- bas 2y agoVery informative. Thank you!
- sangeeth96 2y agoTrue, this should be fine for straightforward stuff but extremely annoying as soon as you have for eg, quoted strings with whitespace in it which is where it breaks. Have to keep that difference in mind when writing scripts. The link I posted in my original reply has a good explanation of this behavior. I was the one who asked the question there.
- wink 2y agoMaybe this helps? Have not tried it. https://blog.winny.tech/posts/multiple-arguments-in-shebang/ https://blog.winny.tech/posts/multiple-arguments-in-shebang/
- dredmorbius 2y agoAnd that on Android env doesn't live in /bin/.