Live data from Hacker News

What does " 2>&1 " mean?

stackoverflow.com

181–190 of 260 posts

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

#181
post #157

Earlier quoted context omitted.

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…

Seems related to the Law of Leaky Abstractions?

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?

#182
post #166

Earlier quoted context omitted.

It's really jarring to see this wave of nostalgia for "the good old days" appear since ~2025. Suddenly these rose tinted glasses have dropped and everything before LLM usage became ubiquitous was a beautiful romantic era of human collaboration, understanding and craftsmanship. I still acutely remember the gatekeeping and hostility of peak stack overflow, and the inanity of churning out jira tickets as fast as possibl…

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…

I don’t think I’ve ever ask a question on Stack Overflow, but I’ve consulted it several time. Even when I’ve not found my exact use case, there’s always something similar or related that gave me the right direction for research (a book or an article reference, the name of a concept to use as keyword,…)

It’s kinda the same feeling when browsing the faq of a project. It gives you a more complete sense of the domain boundaries.

I still prefer to refer to book or SO instead of asking the AI. Coherency and purposefulness matter more to me then a direct answer that may be wrong.

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

#183

Man I miss stack overflow. It feels so much better to ask humans a question then the machine, but it feels impossible to put the lid back on the box.

> It feels so much better to ask humans a question then the machine I could not disagree more! With pesky humans, you have all sorts of things to worry about: - is my question stupid? will they think badly of me if i ask it? - what if they dont know the answer? did i just inadvertantly make them look stupid? - the question i have is related to their current work... i hope they dont see me as a threat! and on and on.…

That’s a level of paranoia that I can’t really understand. I just do my research, then for information I can’t access, don’t know how to access, or can’t comprehend, I reach out. People have the right to not want to share information. If it’s in a work setting and the situation is blocking, I notify my supervisor.

> many word orderings trigger a 'latent space' which activates the "umm, why are you even doing this?" with the implication begin "you really are stupid!"

You may have heard of the XY situation when people asks a Y question only because they have an incorrect answer to X. A question has a goal (unless rethorical) and to the person being asked, it may be confusing. You may have a valid reason to go against common sense, but if the other person is not your tutor or a fellow researcher, he may not be willing to accommodate you and spend his time for a goal he have no context about.

Remember the car wash question for LLMs? Some phrasing have the pattern of a trick question and that’s another thing people watch out for.

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

#184

Earlier quoted context omitted.

You're not wrong, but there's fairly easy ways to deal with filenames containing spaces - usually just enclosing any variable use within double quotes will be sufficient. It's tricker to deal with filenames that contain things such as line breaks as that usually involves using null terminated filenames (null being the only character that is not allowed in filenames). e.g find . -type f -print0

You're not wrong, but at my place, our main repository does not permit cloning into a directory with spaces in it. Three factors conspire to make a bug: 1. Someone decides to use a space 2. We use Python 3. macOS Say you clone into a directory with a space in it. We use Python, so thus our scripts are scripts in the Unix sense. (So, Python here is replacable with any scripting language that uses a shebang, so long as…

These are part of the rituals of learning how a system works, in the same way interns get tripped up at first when they discover ^S will hang an xterm, until ^Q frees it. If you're aware of the history of it, it makes perfect sense. Unix has a personality, and in this case the kernel needs to decide what executable to run before any shell is involved, so it deliberately avoids the complexity of quoting rules.

I'd give this a try, works with any language:

  #!/usr/bin/env -S "/path/with spaces/my interpreter" --flag1 --flag2
Only if my env didn't have -S support, I might consider a separate launch script like:

  #!/bin/sh
  exec "/path/with spaces/my interpreter" "$0" "$@"
But most decent languages seems to have some way around the issue.

Python

  #!/bin/sh
  """:"
  exec "/path/with spaces/my interpreter" "$0" "$@"
  ":"""
  # Python starts here
  print("ok")
Ruby

  #!/bin/sh
  exec "/path/with spaces/ruby" -x "$0" "$@"
  #!ruby
  puts "ok"
Node.js

  #!/bin/sh
  /* 2>/dev/null
  exec "/path/with spaces/node" "$0" "$@"
  */
  console.log("ok");
Perl

  #!/bin/sh
  exec "/path/with spaces/perl" -x "$0" "$@"
  #!perl
  print "ok\n";
Common Lisp (SBCL) / Scheme (e.g. Guile)

  #!/bin/sh
  #|
  exec "/path/with spaces/sbcl" --script "$0" "$@"
  |#
  (format t "ok~%")
C

  #!/bin/sh
  #if 0
  exec "/path/with spaces/tcc" -run "$0" "$@"
  #endif
  
  #include 
  
  int main(int argc, char **argv)
  {
      puts("ok");
      return 0;
  }
Racket

  #!/bin/sh
  #|
  exec "/path/with spaces/racket" "$0" "$@"
  |#
  #lang racket
  (displayln "ok")
Haskell

  #!/bin/sh
  #if 0
  exec "/path/with spaces/runghc" -cpp "$0" "$@"
  #endif
  
  main :: IO ()
  main = putStrLn "ok"
Ocaml (needs bash process substitution)

  #!/usr/bin/env bash
  exec "/path/with spaces/ocaml" -no-version /dev/fd/3 "$@" 3

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

#186

Earlier quoted context omitted.

> Also the choice of quotes changing behavior is a thing in: In those languages they change what's contained in the string. Not how many strings you get. Or what the strings from that string look like. ($@ being an extreme example)

> $@ being an extreme example From the bash man page via StackOverflow: > @ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and t…

Complex and bash script should not be in the same sentence. If a script you have is becoming complex, that’s an hint to use an anemable programming language with proper data types and structures.

Shell scripts is for automating shell sessions.

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

#187
post #166

Earlier quoted context omitted.

It's really jarring to see this wave of nostalgia for "the good old days" appear since ~2025. Suddenly these rose tinted glasses have dropped and everything before LLM usage became ubiquitous was a beautiful romantic era of human collaboration, understanding and craftsmanship. I still acutely remember the gatekeeping and hostility of peak stack overflow, and the inanity of churning out jira tickets as fast as possibl…

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 that the feedback is almost instant and there are no difficult personalities to deal with.

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

#188

Earlier quoted context omitted.

You're not wrong, but at my place, our main repository does not permit cloning into a directory with spaces in it. Three factors conspire to make a bug: 1. Someone decides to use a space 2. We use Python 3. macOS Say you clone into a directory with a space in it. We use Python, so thus our scripts are scripts in the Unix sense. (So, Python here is replacable with any scripting language that uses a shebang, so long as…

What a headache! My practical view is to avoid spaces in directories and filenames, but to write scripts that handle them just fine (using BASH - I'm guilty of using it when more sane people would be using a proper language). My ideological view is that unix/POSIX filenames are allowed to use any character except for NULL, so tools should respect that and handle files/dirs correctly. I suppose for your usage, it'd be…

For the BSDs and Linux, I believe that shebang are intepreted by the kernel directly and not by the shell. /usr/bin/env and /bin/sh are guaranteed by POSIX to exists so your solution is the correct one. Anything else is fragile.

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

#189
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.

> At least allow us to use names instead of numbers

Many people probably think in terms of "fd 0" and "fd 1" instead of "standard in" and "standard out", but should you wish to use names at least on modern Linux/BSD systems do:

  echo message >/dev/stdout
  echo error_message >/dev/stderr

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

#190

Awesome. Next week I will forget it again.

While you're still thinking about it, make sure to bookmark the "redirections" section of the manual. [0] Also useful might be the "pipelines" section [1] to remind you of the "|&" operator.

[0] https://www.gnu.org/software/bash/manual/bash.html#Redirecti...>

[1] https://www.gnu.org/software/bash/manual/bash.html#Pipelines...>

Post reply on HN