@b0rk @dlatchx I've been saying for years that there ought to be an environment variable to disable stdio buffering. Then instead of a weird trick you would
NO_STDOUT_BUFFERING=1 cmd | grep whatever
(or alias cmd='NO_STDOUT_BUFFERING=1 cmd' or something like that.)
Apparently NetBSD even has this feature. Not Linux though.
https://blog.plover.com//Unix/stdio-buffering.html
https://blog.plover.com/Unix/stdio-buffering-2.html
@nabijaczleweli @b0rk @dlatchx It has been invented several times, in several ways, as I discussed in the second article.
The implementation of stdbuf is somewhat ridiculous though. It forces the process to dynamically load a completely different standard I/O library. Whereas if my environment variable solution had been baked in, no ridiculousness would be required.
@mjd @b0rk @dlatchx every stdbuf-like implementation, ever (i have just validated this), consists of a libstdbuf (except for NetBSD which has this built into libc), which has a constructor that parses the environment variables and calls setvbuf(). any other implementation would be utter lunacy
all /bin/stdbuf does is LD_PRELOAD=libstdbuf.so; _STDBUF_I=argv[optind]; exec(argv + 1)
(here's a sample implementation (although a bad one for a demo, because this is really size-optimised; 0BSD): https://git.sr.ht/~nabijaczleweli/voreutils/tree/trunk/item/lib/libstdbuf.cpp#L14; and of /bin/stdbuf: https://git.sr.ht/~nabijaczleweli/voreutils/tree/trunk/item/cmd/stdbuf.cpp#L31. all of them are, functionally, identical)
@nabijaczleweli @b0rk @dlatchx Yes, thanks. I have posted a correction to the blog article at https://blog.plover.com/Unix/stdio-buffering-2.html , crediting you. Let me know if you would like it phrased differently.
@mjd well the markdown linkification broke but otherwise this is reasonable
@nabijaczleweli Thanks for the correction.