Hi Doug, At 2024-10-09T18:48:11-0400, Douglas McIlroy wrote: > > > "printf '%s\n%s\n' '.kern 0' '.ss 12 0' | groff -mandoc -Z - " > > > > [...] > > The foregoing is also revealing of a low level of sophistication with > > printf(1). > > True. But why harness marginal feaures for such small benefit? > Unrewarding sophistication should be disparaged, not flaunted. I > would say that using printf rather than echo is a sign of (arguably > flaunted) sophistication.
Without admitting or denying that I might sometimes succumb to displays of...flauntation, there's an important practical issue here. The value of printf(1) lies not in its firepower (which is indeed supercharged for many [most?] shell applications) but its _predictability_. printf(1) is a POSIX invention because of an old BSD vs. System V conflict over how `echo` should behave. Approximately, BSD said echo should handle a `-n` option to suppress a newline at the end of its output. System V said that echo should support a set of escape sequences instead, including `\c` which would suppress a newline at the end of output. (I wonder where _that_ inspiration came from... ;-) ) Both sides refused to budge, which led to the ugly situation of there being no portable way to write things from the shell. The Korn shell swooped in and squatted on "print", I guess in a gambit to be the One Shell to Which Everyone Should Switch At Once. Of course, it had a price tag attached to it, so much of the world raised the exact middle finger such a grasping proposal earned. Worse, I can't ever remember the rules about how a backslash is interpreted in echo...do I need to double it? Should I not even bother because it's not going to be portable anyway? My very rough rule of thumb (and I don't promise that all of groff's test scripts follow this principle perfectly) is that echo is okay if no literal `\` appears in its argument list. If one does, I need to switch to printf(1). If a shell variable might expand to include a `\`, I also don't know what to expect and typically retreat to printf(1) in fear. Regards, Branden
signature.asc
Description: PGP signature