News for hackers. Stuff that matters.
Re:What does " 2>&1 " mean? by goku12 on Friday February 27, 2026 @02:45AM (#47177742)
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 using macros. And this fact is not hidden from us. You know that all of them ultimately expand to the limited number of special forms.

The shell syntactical sugars also have some weird gotchas. The &2>&1 question and its answer are a good example of that. You're just trading one complexity (low level knowledge) for another (the long list of syntax rules). Shell languages break the rule of not letting abstractions get in the way of insight and intuitiveness.

I know that people will argue that shell languages are not programming languages, and that terseness is important for the former. And yet, we still have people complaining about it. This is the programmer ego and the sysadmin ego of people clashing with each other. After all, nobody is purely just one of those two.

Re:What does " 2>&1 " mean? by skywal_l on Friday February 27, 2026 @03:16AM (#47177976)
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 implementations. Those abstractions used to make perfect sense for those with prior knowledge but can also carry subtle bias which makes their use error prone for non initiated users.

Re:What does " 2>&1 " mean? by taneq on Friday February 27, 2026 @04:59AM (#47178692)
Seems related to the Law of Leaky Abstractions?
Re:What does " 2>&1 " mean? by carlmr on Friday February 27, 2026 @07:05AM (#47179575)
It's not necessarily a leaky abstraction. But a lack of _knowledge in the world_.

The abstraction may be great, the problem is the lack of intuitive understanding you can get from super terse, symbol heavy syntax.

Re:What does " 2>&1 " mean? by lukan on Friday February 27, 2026 @09:01AM (#47180553)
I like abstractions when they hide complexity I don't need to see nor understand to get my job done. But if abstractions misdirect and confuse me, they are not syntactical sugar to me, but rather poison.

(But I won't claim that I am always able to strike the right balance here)

Re:What does " 2>&1 " mean? by shevy-java on Friday February 27, 2026 @10:01AM (#47181285)
> Those abstractions used to make perfect sense for those with prior knowledge but can also carry subtle bias which makes their use error prone for non initiated users.

I don't think 2>&1 ever made any sense.

I think shell language is simply awful.

Re:What does " 2>&1 " mean? by goku12 on Friday February 27, 2026 @02:59PM (#47184804)
> I don't think 2>&1 ever made any sense.

It's not that hard. Consider the following:

  $ command &2>&1
The shell thinks that you're trying to run the portion before the & (command) in the background and the portion after the & (2>&1) in the foreground. There is just one problem. The second part (2>&1) means that you're redirecting stderr/fd2 to stdout/fd1 for a command that is to follow (similar to how you set environment variables for a command invocation). However, you haven't specified the command that follows. The second part just freezes waiting for the command. Try it and see for yourself.

  $ command 2>1
Here the shell redirects the output of stderr/fd2 to a file named 1. It doesn't know that you're talking about a file descriptor instead of a filename. So you need to use &1 to indicate your intention. The same confusion doesn't happen for the left side (fd2) because that will always be a file descriptor. Hence the correct form is:

  $ command 2>&1
> I think shell language is simply awful.

Honestly, I wish I could ask the person who designed it, why they made such decisions.

Re:What does " 2>&1 " mean? by wahern on Friday February 27, 2026 @07:28PM (#47188210)
> Honestly, I wish I could ask the person who designed it, why they made such decisions.

https://web.archive.org/web/20250115051355/https://www.bell-...

https://www.cs.dartmouth.edu/~doug/sieve/sieve.pdf

https://www.in-ulm.de/~mascheck/bourne/index.html#origins

They also include citations to papers by Thompson, Bourne, and others.

Re:What does " 2>&1 " mean? by reacweb on Friday February 27, 2026 @03:11AM (#47177946)
make 2>&1 | tee m.log is in my muscle memory, like adding a & at the end of a command to launch a job, or ctrl+z bg when I forget it, or tar cfz (without the minus so that the order is not important). Without this terseness, people would build myriads of personal alias.

This redirection relies on foundational concepts (file descriptors, stdin 0, stdout 1, stderr 2) that need to be well understood when using unix. IMO, this helps to build insight and intuitiveness. A pipe is not magic, it is just a simple operation on file descriptors. Complexity exists (buffering, zombies), but not there.

Re:What does " 2>&1 " mean? by cpach on Friday February 27, 2026 @06:16AM (#47179188)
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.

Re:What does " 2>&1 " mean? by skywhopper on Friday February 27, 2026 @06:50AM (#47179462)
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, and attempt to have a shared glue language usable across many platforms. Most of the special syntax was developed long before Google existed.

So, sure, there are practical issues with details like this. And yet, it is simple. And there are simple methods for learning and retaining little tidbits like this over time if you care to do so. Bash and its cousins aren’t going away, so take notes, make a cheat sheet, or work on a better replacement (you’ll fail and make the problem worse, but go ahead).

Re:What does " 2>&1 " mean? by simoncion on Friday February 27, 2026 @09:06AM (#47180610)
Yeah, seriously. It's as if people want to playact as illiterate programmers.

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? by goku12 on Friday February 27, 2026 @03:29PM (#47185148)
> The "Redirections" section of the manual [0] is just seven US Letter pages.

"Just" seven US Letter pages? You're talking about redirections alone, right? How many such features exist in Bash? I find Python, Perl and even Lisps easier to understand. Some of those languages wouldn't have been even conceived if shell languages were good enough.

There is another shell language called 'execline' (to be precise, it's a replacement for a shell). The redirections in its commands are done using a program named 'fdmove' [1]. It doesn't leave any confusion as to what it's actually doing. fdmove doesn't mention the fact that it resorts to FD inheritance to achieve this. However, the entire 'shell' is based on chain loading of programs (fork, exec, FD inheritance, environment inheritance, etc). So fdmove's behavior doesn't really create any confusion to begin with. Despite execline needing some clever thinking from the coder, I find it easier to understand what it's actually doing, compared to bash. This is where bash and other POSIX shell languages went wrong with abstractions. They got carried away with them.

[1] https://www.skarnet.org/software/execline/fdmove.html

Re:What does " 2>&1 " mean? by simoncion on Friday February 27, 2026 @05:40PM (#47186772)
> "Just" seven US Letter pages?

Yes. It's the syntax alongside prose explaining the behavior in detail. Go give it a read.

If you want documentation that's done up in the "modern" style, then you'll prefer that one-page cheat sheet that that guy made. I find that "modern" documentation tends to leave it up to each reader to discover the non-obvious parts of the behavior for themselves.

> I find Python ... easier to understand.

Have you read the [0] docs for Python's 'subprocess' library? The [1] docs for Python's 'multiprocess' library? Or many of the other libraries in the Python standard library that deal with nontrivial process and I/O management? Unless you want to underdocument and leave important parts of the behavior for users to incorrectly guess, such documentation is going to be much larger than a cheat sheet would be.

[0] ...twenty-five pages of...

[1] ...fifty-nine pages of...

Re:What does " 2>&1 " mean? by goku12 on Saturday February 28, 2026 @03:34AM (#47192325)
> Yes. It's the syntax alongside prose explaining the behavior in detail. Go give it a read.

Bold of you to assume that I or the others didn't. I made my statement in spite of reading it. Not because I didn't read it. So my opinion is unchanged here.

The point here is simple. Documentation is a very important addition. But you can't paper over other deficiencies with documentation, especially if you find yourself referring the same documentation again and again. It's an indication that you're dealing with an abstraction that can't easily be internalized. Throwing the book at everyone isn't a good solution to every problem.

> Have you read the [0] docs for Python's 'subprocess' library? The ...

Yes, I have! All of those. Their difference with bash documentation is that you get the idea in a single glance. I spend much less time wondering how to make sense of it all. Python's abstractions are well thought out, carefully selected, consistently and orthogonally implemented and stays out of the way - something I can hardly say about bash. If that's not enough for you, Python has something that bash lacks - PEPs. The documents that neatly outline the rationale behind their decisions. That's what a lot of programmers want to know and every programmer should know.

Fun fact: The Epstein files contain a copy of the bash manual! Of course they weren't involved in his crimes. It was just one of the documents found on his system. A sysadmin is believed to have downloaded it for reference. But it's telling that it wasn't the Python manual, or the Perl manual, or something else. Meanwhile, I don't really think that Epstein was running Linux on his system.

> Unless you want to underdocument and leave important parts of the behavior for users to incorrectly guess, such documentation is going to be much larger than a cheat sheet would be.

If properly designed, such expansive documentation would be unnecessary, as they would be obvious even with the abstractions. For example when you use a buffer abstraction in modern languages, you have a fairly good idea what it does and why you need it, even though you may not care about its exact implementation details. That's the sort of quality where bash and other POSIX shells fail on several counts. In fact, check how many other shells break POSIX compatibility to solve this problem. Fish and nushell, for example.

"The developer is too lazy to read the documentation" isn't the appropriate stance to assume when so many are expressing their frustration and displeasure at it. At some point, you have to concede that there are genuine problems that cannot be blamed on the developer alone.

Re:What does " 2>&1 " mean? by simoncion on Saturday February 28, 2026 @05:22AM (#47193270)
> But you can't paper over other deficiencies with documentation, especially if you find yourself referring the same documentation again and again. It's an indication that you're dealing with an abstraction that can't easily be internalized.

> Their difference with bash documentation is that you get the idea in a single glance.

> If properly designed, such expansive documentation would be unnecessary, as they would be obvious even with the abstractions.

What is it the kids say? "Tell me you don't make use of 'multiprocessing', 'subprocess', and other such inherently-complicated modules without telling that you don't..."? Well, it's either that, or you that often use them, and rarely use bash I/O redirections... because, man, the docs for just the 'subprocess.Popen' constructor are massive and full of caveats and warnings.

Re:What does " 2>&1 " mean? by goku12 on Saturday February 28, 2026 @10:31PM (#47203404)
You're resorting to non sequiturs, nitpicking and vague assertions to just skirt around the point here. Python syntax rarely confuses people as much as bash does. Look at this entire discussion list for example.

subprocess module isn't a reasonable example to the contrary, because it isn't Python's syntactical sugar that makes it confusing. And even in case of modules that aren't well designed, the language developers and the community strive to provide a more ergonomic alternative.

But instead of addressing the point, you decided to make it about me and my development patterns based on some wild reasoning. But that's not surprising because this started with you asserting that it's the developers' fault that bash appears so confusing to them. Just some worthless condescension instead of staying on topic. What a disgrace!

Re:What does " 2>&1 " mean? by darkwater on Friday February 27, 2026 @06:39AM (#47179371)

  ? (defun even(num) (= (mod num 2) 0))
  ? (filter '(6 4 3 5 2) #'even)
I'm zero Lisp expert and I don't feel comfortable at all reading this snippet.
Re:What does " 2>&1 " mean? by goku12 on Friday February 27, 2026 @03:13PM (#47184955)
This:

> I'm zero Lisp expert

and this:

> I don't feel comfortable at all reading this snippet

are related. The comfort in reading Lisp comes from how few syntactic/semantic rules there are. There's a standard form and a few special forms. Compare that to C - possibly one of the smallest popular languages around. How many syntactical and semantic rules do you need to know to be a half decent C programmer?

If you look at the Lisp code, it has just 2 main features - a tree in the form of nested lists and some operations in prefix notation. It needs some getting used to for regular programmers. But it's said that programming newbies learn Lisps faster than regular programming languages, due to the fewer rules they have to remember.

Re:What does " 2>&1 " mean? by darkwater on Saturday February 28, 2026 @06:08AM (#47193685)
The initial discussion was about bash syntax. I do understand that exceptions to rules are what make a language more complicated (either human or computer language, it doesn't matter), but also a language barrier of entry is a very important factor in how complicated a language is.
Re:What does " 2>&1 " mean? by miki123211 on Friday February 27, 2026 @09:13AM (#47180676)
Shell is optimized for the minimal number of keystrokes (just like Vim, Amadeus and the Bloomberg Terminal are optimized for the minimum number of keystrokes. Programming languages are primarily optimized for future code readability, with terseness and intuitiveness being second or third (depending on language).