On the other hand, pipe “|” is brilliant!
What does " 2>&1 " mean?
191–200 of 260 posts
Re: What does " 2>&1 " mean?
#192Re: What does " 2>&1 " mean?
#193stackoverflow, how quaint. Anyone here remember when it was actually useful and questions like the one featured could be asked and answered?
Re: What does " 2>&1 " mean?
#194The comments on stackoverflow say the words out of my mouth so I'll just copy & paste here: > but then shouldn't it rather be &2>&1? > & is only interpreted to mean "file descriptor" in the context of redirections. Writing command &2>& is parsed as command & and 2>&1 That's where all the confusion comes from. I believe most people can intuitively understand > is redirection, but the asymmetrical use of & throws them…
Although PowerShell borrows the syntax, it (as usual!) completely screws up the semantics. The examples in the docs [1] show first setting descriptor 2 to descriptor 1 and then setting descriptor 1 to a newly opened file, which of course is backwards and doesn't give the intended result in Unix; e.g. their example 1: dir C:\, fakepath 2>&1 > .\dir.log Also, according to the same docs, the operators "now preserve the…
It's also not a file descriptor. It's a PowerShell Stream, of which there are five? you can redirect to that are similar to log levels.
Re: What does " 2>&1 " mean?
#195Redirects 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.
It would be great to be able to open a socket in bash[^1] and pass it to another program to read/write from without having an extra socat process and pipes running (and the buffering, odd flush behaviour, etc.). It would be great if programs expected to receive input file arguments as open fds, rather than providing filenames and having the process open them itself. Sandboxing would be trivial, as would understanding the inputs and outputs of any program.
It's frustrating to me because the underlying unix system supports this so well, it's just the conventions of userspace that get in the way.
[^1]: I know about /dev/tcp, but it's very limited.
Re: What does " 2>&1 " mean?
#196Earlier quoted context omitted.
Probably people complaining about AI today were fine with Stack Overflow before and didn't have anything to complain about back then. I also had a better experience with Stack Overflow over AI. It's been unable to tell me that I couldn't assign a new value to my std::optional in my specific case, and kept hallucinating copy constructor rules. A Stack Overflow question matching my problem cleared that up for me. Somet…
> A Stack Overflow question matching my problem cleared that up for me. Perhaps if there was no question already available you'd have had a different experience. Getting clearly written and specific questions promptly closed as duplicates of related, yet distinct issues, was part of the fun. I find that AI hallucinates in the same way that someone can be very confident and wrong at the same time, with the difference…
And sometimes that someone can be you, and AI is notoriously bad at telling you that you're wrong (because it has to please people)
Re: What does " 2>&1 " mean?
#197Earlier quoted context omitted.
Isn't that because of posix?
Powershell is not posix compliant and does not pretend to be. Like conditionals using `()` instead of `[]` is already a clear departure from posix
Re: What does " 2>&1 " mean?
#198Earlier quoted context omitted.
This is probably one of the reasons why many find POSIX shell languages to be unpleasant. There are too many syntactical sugars that abstract too much of the underlying mechanisms away, to the level that we don't get it unless someone explains it. Compare this with Lisps, for example. There may be only one branching construct or a looping construct. Yet, they provide more options than regular programming languages us…
There must be a law of system design about this, because this happens all the time. Every abstraction creates a class of users who are powerful but fragile. People who build a system or at least know how it works internally want to simplify their life by building abstractions. As people come later to use the system with the embedded abstractions, they only know the abstractions but have no idea of the underlying impl…
(But I won't claim that I am always able to strike the right balance here)
Re: What does " 2>&1 " mean?
#199Earlier quoted context omitted.
Are you sure you understood the comment you replied to? I agree that 2>&1 is not complex. But I think I speak for many Bash users when I say that this idiom looks bad, is hard to Google, hard to read and hard to memorize.
It’s not like someone woke up one morning and decided to design a confusing language full of shortcuts to make your life harder. Bash is the sum of decades of decisions made, some with poor planning, many contradictory, by hundreds of individuals working all over the world in different decades, to add features to solve and work around real world problems, keep backwards compatibility with decades of working programs,…
The "Redirections" section of the manual [0] is just seven US Letter pages. This guy's cheat sheet [1] that took me ten seconds to find is a single printed page.
[0] https://www.gnu.org/software/bash/manual/html_node/Redirecti...>
[1] https://catonmat.net/ftp/bash-redirections-cheat-sheet.pdf>
Re: What does " 2>&1 " mean?
#200Normally when you do something like command > file.txt, you’re only capturing the normal output — errors still go to your screen.
2>&1 is how you say: “send the error pipe into the same place as the normal output pipe.” Breaking it down without jargon: • 2 means “the error output” • > means “send it to” • &1 means “wherever the normal output is currently going” (the & just means “I’m referring to a pipe, not a file named 1”)