Live data from Hacker News

A surprise with how '#!' handles its program argument in practice

utcc.utoronto.ca

111–116 of 116 posts

Re: A surprise with how '#!' handles its program argument in practice

#111

Earlier quoted context omitted.

You can have your cake (use multiple venvs) and eat it (flexibility) too. `source venv/bin/activate` from your .sh files will cause `/usr/bin/env python3` to use the python3 located in your venv. Switching between venvs is easy too. just call `deactivate` when one venv is activated. It drops you out of the venv. You can then cleanly `source venv2/bin/activate`.

It feels like you're telling me that I'm holding my phone wrong. I don't like sourcing things into my environment. I've worked this way for years. I think the idea of 'activating' and 'deactivating' an environment is an anti-pattern. But I also work on HPC clusters where all of the configuration about paths is handled by the environment. Because of this, I've learned the hard way that for my workflows, it's far too e…

> It feels like you're telling me that I'm holding my phone wrong.

I'm sorry you feel that way.

Ultimately, it is your code and you can do with it whatever you like.

...until your code becomes company code or open sourced. Then your way becomes a hinder to other developers.

> I don't like sourcing things into my environment. I've worked this way for years. I think the idea of 'activating' and 'deactivating' an environment is an anti-pattern.

I completely agree with you. The whole concept of a venv is great! But the concept of needing to source an activation script is... just... completely foreign to me. It took me months to understand that's the way it was intended to work, and more years to stop fighting it.

> I sometimes will have to run multiple programs (that have their own venvs) and pipe data between them.

Me too! I pipe data around all the time because it's amazingly fast and amazingly awesome to just hook up a pipeline. It can be done with venvs, too. Consider this:

    #!/usr/bin/env bash
    set -euo pipefail
    jq '.'  >(source venv2/bin/activate; ./script2)
Here, script1 (which requires the first venv) might produce some JSON stuff to be processed by `jq`, then pipe that to script2 (which requires the second venv).

I'm curious how you do it though.

Re: A surprise with how '#!' handles its program argument in practice

#112

Earlier quoted context omitted.

UTF-8 is a text format with no BOM. Just like ASCII doesn't support a BOM. The BOM is a UTF-16 or UTF-32 thing, so "UTF-8 with BOM" is a binary file that happens to contain some UTF-8 strings as well. Since it's not a text file, it makes sense that utilities expecting text files don't handle it.

Eh? A utf8 file starting with ZERO WIDTH NO-BREAK SPACE is not a text file? How do you figure that?

If it starts with 0xFE 0xFF, but is otherwise UTF-8 instead of UTF-16, it's a binary file. If it starts with 0xEF 0xBB 0xBF, it's a text file with a ZERO WIDTH NO-BREAK SPACE at the start.

Re: A surprise with how '#!' handles its program argument in practice

#113

> You're using a suspiciously old browser Does the author not like Firefox or what?

That page[0] should explain the reasoning behind the redirect. There's a separate redirect[1] if you have a never version reported but are missing headers. Seems to be a fairly custom attempt at keeping poorly written scrapers off the site. curl works just fine for me. (I found these redirect URLs by manually setting the user agent header in curl) Fun idea. What's your browser's user agent? You might have an extensio…

Yeah, I kind of understand the author, it just sucks to be on the receiving end. I use Firefox ESR 115, with this UA header: "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0"

Re: A surprise with how '#!' handles its program argument in practice

#114

Kind of an adjacent aside, I kind of love how many languages now work with shebangs for creating user scripts... Go, Rust, C#, Deno (TS/JS) etc. The vast majority of my shell/user scripts are now in TS with Deno... The only thing I do wish worked better is that VS Code would look at the shebang to determine a file's language without a file extension. Also works nicely with project automation and CI/CD integration as…

combined with nix shebangs, it's amazing to just code and go little scripts with zero dependency setup

Re: A surprise with how '#!' handles its program argument in practice

#115

Earlier quoted context omitted.

Eh? A utf8 file starting with ZERO WIDTH NO-BREAK SPACE is not a text file? How do you figure that?

If it starts with 0xFE 0xFF, but is otherwise UTF-8 instead of UTF-16, it's a binary file. If it starts with 0xEF 0xBB 0xBF, it's a text file with a ZERO WIDTH NO-BREAK SPACE at the start.

> If it starts with 0xFE 0xFF, but is otherwise UTF-8 instead of UTF-16, it's a binary file

Sure, but who does this? All the Microsoft tooling writes 0xEF 0xBB 0xBF if you output utf8 with a BOM.

Re: A surprise with how '#!' handles its program argument in practice

#116

Earlier quoted context omitted.

`#!/usr/bin/env bash` is the most portable form for executing it from $PATH

I raise you a https://www.felesatra.moe/blog/2021/07/03/portable-bash-sheb... Pedantic, but "#!" and "portable" don't belong in the same sentence

The script you posted is only portable in theory and not in practice. Executing it while using a non-POSIX shell like Elvish (even without having it as a default shell) makes it immediately fail.

Meanwhile, `#!/usr/bin/env` is completely portable in the practical sense. Even systems with non-standard paths like NixOS, Termux and GoboLinux patch in support for it specifically.

Post reply on HN