Live data from Hacker News

What does " 2>&1 " mean?

stackoverflow.com

71–80 of 260 posts

Re: What does " 2>&1 " mean?

#71
post #11

It's a reminder of how archaic the systems we use are. File descriptors are like handing pointers to the users of your software. At least allow us to use names instead of numbers. And sh/bash's syntax is so weird because the programmer at the time thought it was convenient to do it like that. Nobody ever asked a user.

> bash's syntax is so weird What should be the syntax according to contemporary IT people? JSON? YAML? Or just LLM prompt?

Nushell, Powershell, Python, Ruby, heck even Perl is better. Shell scripting is literally the worst language I've ever seen in common use. Any realistic alternative is going to be better.

Re: What does " 2>&1 " mean?

#72
post #11

It's a reminder of how archaic the systems we use are. File descriptors are like handing pointers to the users of your software. At least allow us to use names instead of numbers. And sh/bash's syntax is so weird because the programmer at the time thought it was convenient to do it like that. Nobody ever asked a user.

Who do you imagine the users were back when it was being developed?

Re: What does " 2>&1 " mean?

#73
post #11

It's a reminder of how archaic the systems we use are. File descriptors are like handing pointers to the users of your software. At least allow us to use names instead of numbers. And sh/bash's syntax is so weird because the programmer at the time thought it was convenient to do it like that. Nobody ever asked a user.

It should be a lesson to learn on how simple, logical and reliable tools can last decades.

… Or how hard it is to replace archaic software that’s extremely prevalent.

Re: What does " 2>&1 " mean?

#74

Earlier quoted context omitted.

> bash's syntax is so weird What should be the syntax according to contemporary IT people? JSON? YAML? Or just LLM prompt?

Trying to be language agnostic: it should be as self-explanatory as possible. 2>&1 is all but. Why is there a 2 on the left, when the numbers are usually on the right. What's the relationship between 2 and 1? Is the 2 for std err? Is that `&` to mean "reference"? The fact you only grok it if you know POSIX sys calls means it's far from self explanatory. And given the proportion of people that know POSIX sys calls amo…

POSIX has a manual for shell. You can read 99% of it without needing to know any syscalls. I'm not as familiar with it but Bash has an extensive manual as well, and I doubt syscall knowledge is particularly required there either.

If your complaint is "I don't know what this syntax means without reading the manual" I'd like to point you to any contemporary language that has things like arrow functions, or operator overloading, or magic methods, or monkey patching.

Re: What does " 2>&1 " mean?

#75
post #21

Redirects are fun but there are way more than I actually routinely use. One thing I do is the file redirects. diff I do that with diff <(xxd -r file.bin) <(xxd -r otherfile.bin) sometimes when I should expect things to line up and want to see where things break.

Process substitution and calling it file redirect is a bit misleading because it is implemented with named pipes which becomes relevant when the command tries to seek in them which then fails.

Also the reason why Zsh has an additional =(command) construct which uses temporary files instead.

Re: What does " 2>&1 " mean?

#76
post #62

Earlier quoted context omitted.

Interesting. Is this just literally “fun”, or do you see real world use cases?

Multiple levels of logging, all of which you want to capture but not all in the same place.

Wasn't the idiomatic way the `-v` flag (repeated for verbosity). And then stderr for errors (maybe warning too).

Re: What does " 2>&1 " mean?

#77
post #11

It's a reminder of how archaic the systems we use are. File descriptors are like handing pointers to the users of your software. At least allow us to use names instead of numbers. And sh/bash's syntax is so weird because the programmer at the time thought it was convenient to do it like that. Nobody ever asked a user.

I quite like how archaic it is. I am turned off by a lot of modern stuff. My shell is nice and predictable. My scripts from 15 years ago still work just fine. No, I don't want it to get all fancy, thanks.

Re: What does " 2>&1 " mean?

#79
post #11

It's a reminder of how archaic the systems we use are. File descriptors are like handing pointers to the users of your software. At least allow us to use names instead of numbers. And sh/bash's syntax is so weird because the programmer at the time thought it was convenient to do it like that. Nobody ever asked a user.

It should be a lesson to learn on how simple, logical and reliable tools can last decades.

It's more like how the need for backwards compatibility prevents bad interfaces from ever getting improved.

Re: What does " 2>&1 " mean?

#80
post #11

It's a reminder of how archaic the systems we use are. File descriptors are like handing pointers to the users of your software. At least allow us to use names instead of numbers. And sh/bash's syntax is so weird because the programmer at the time thought it was convenient to do it like that. Nobody ever asked a user.

Who do you imagine the users were back when it was being developed?

People who were not that one programmer?

Even if you're a programmer, that doesn't mean you magically know what other programmers find easy or logical.

Post reply on HN