A digression on echo. - Printable Version +- nixers (https://nixers.net) +-- Forum: Operating Systems & Administration (https://nixers.net/Forum-Operating-Systems-Administration) +--- Forum: Other *nix-like OSes & POSIX related (https://nixers.net/Forum-Other-nix-like-OSes-POSIX-related) +--- Thread: A digression on echo. (/Thread-A-digression-on-echo--2311) |
A digression on echo. - seninha - 20-04-2020 After commenting on this thread I remembered a text on echo that Brian Kernighan and Rob Pike wrote in their book The UNIX Programming Environment called A digression on echo. The single option -n is not like other options in other utilities. For example, while most utilities use getopt(3) to get the options, echo(1) should not use it, since a gotten option could be an argument to be echoed. See how OpenBSD implement echo, for example: Code: #include <stdio.h> Other than -n, modern echo implementations also add a new complexity: the C-like backslash sequences like '\n' and '\t'. Some echo implementations (such as OpenBSD's) just ignore them, but some (such as Bash built-in) don't. Here is another digression on echo about this very topic, by Doug Mcllroy, best known for proposing the UNIX pipelines and creating several UNIX tools: There is, however, another utility that does not print newlines when not asked for and that does interpret C-like backslash sequences: printf(1) PS: I don't know the right forum to post it. I posted it here in the Philosophy forum since I think that the question on bloatedness and feature creep are related to UNIX Philosophy. RE: A digression on echo. - jkl - 20-04-2020 This seems to be one of the better examples on how Unix defaults to non-predictive behavior sometimes. RE: A digression on echo. - z3bra - 20-04-2020 Good job digging up the history behind it. it was a really interesting read ! Reading the source code for echo under different implementations has been an exercise many people have taken to compare code complexity (obviously, GNU "wins" here). I personally only use "echo" to print out debug statements, or quickly output a variable name. For example, all my scripts feature this snippet: Code: usage() { Whenever I need to print out formatted stuff, printf(1) is my goto as it is much more convenient. RE: A digression on echo. - seninha - 20-04-2020 (20-04-2020, 03:40 PM)z3bra Wrote: Reading the source code for echo under different implementations has been an exercise many people have taken to compare code complexity (obviously, GNU "wins" here). This comparison remembered me of this meme, based on longcat. RE: A digression on echo. - jkl - 20-04-2020 I wonder how much of the GNU code is a try to circumvent the limitations imposed by its libc compared to Plan 9’s. RE: A digression on echo. - z3bra - 21-04-2020 Hahaha awesome meme ! (20-04-2020, 04:33 PM)jkl Wrote: I wonder how much of the GNU code is a try to circumvent the limitations imposed by its libc compared to Plan 9’s. I think they're more trying to circumvent their own coding guidelines than the libc… Which is even more terrifying if you ask me. I mean. what the hell is this? or that? I'm speechless… RE: A digression on echo. - jkl - 21-04-2020 "GNU's Not Unix. And here's how we mean that." RE: A digression on echo. - twee - 21-04-2020 Reading the GNU coding standards was what convinced me to move back to OpenBSD, after having had to move back to Linux for certain software support which is no longer an issue. In particular, this paragraph: Quote: For instance, Standard C says that nearly all extensions to C are It reads to me both as quite immature and as something of a "Microsoftian" attitude. Every time I see GNU code I find it offputting, and I wouldn't even really consider myself a UNIX purist. RE: A digression on echo. - seninha - 28-11-2020 Another GNUism that turned out into a meme: GNU true(1), an utility that is supposed to return zero (true), can return non-zero (false). That's because it does way more than return 0. Compare OpenBSD implementation of true(1) with GNU's. |