what problems have you run into with redirection in the terminal? so far I have:

1. trying to read and write to the same file overwrites the file with an empty version (like `grep blah file.txt > file.txt`)
2. `sudo echo blah > /etc/file.txt` doesn't work (you can `echo blah | sudo tee file.txt` instead)
3. remembering where you're supposed to put 2>&1 to redirect stderr to stdout is hard

Follow

@b0rk

The behaviour of stdout handling (at least in glibc) depends on whether it's a terminal: terminals get line buffering, pipes and regular files get a fixed-size buffer. This means that a program that runs for a long time and slowly outputs stuff to stdout will appear to be stuck when its output is redirected to a file _or even piped to `tee`_.

@b0rk

For that reason also running `foo` and `cat | foo` will exhibit different effective stdin buffering behaviour -- in the former case `foo` will see your input line-by-line while in the latter likely will see it only once you send EOF (the buffer is iirc 16KiB).

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.