by setra · 10y ago · 0 comments
Can I take the OpenBSD userland and untar, configure, build and run in cygwin? Nope. You have proven my point. Nobody uses the little SYS V version.
One hint as to why the GNU version is so "long" and "messy":
/* System V machines already have a /bin/sh with a v9 behavior.
Use the identical behavior for these machines so that the
existing system shell scripts won't barf. */
bool do_v9 = DEFAULT_ECHO_TO_XPG;
It has to run in environments that others do not in order to provide full functionality, so it has to implement that functionality.And Unix Fifth Edition, imbued with the cleanliness of Ken Thompson's ghost? Yeah, that's lovely, but not only is it again, of limited utility and portability across idiosyncratic modern environments, but it's full of bugs dating to an era where simplicity was valued above handling all inputs. In 1983, crashing on a bad input wasn't even generally understood to BE a bug, much less extremely dangerous especially in core system utilities.
Does the option really belong in echo? Who knows, but it's certainly been useful to me.
UNIX fifth edition goes for absolute minimalism. Echo in Plan 9 is apparently used enough that it's worthwhile to optimize the number of times write is called. FreeBSD echo looks like someone just learned about writev. OpenBSD's seem like the sanest of the minimalists.
What's the takeaway for you?
For many people, from the writers of the Single Unix Specification to the Debian Policy people, the take-away was and is use printf, for nigh on 20 years now.
* https://www.debian.org/doc/manuals/debian-reference/ch12.en....
* http://pubs.opengroup.org/onlinepubs/7908799/xcu/echo.html#t...
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=490605
* http://www.in-ulm.de/~mascheck/various/echo+printf/
* http://mywiki.wooledge.org/Bashism#Builtins
$ printf "This\tis an\nexample\n"
This is an
example
You can also use the usual C-style printf parameters as well: $ printf "This is %-20s example\n" another
This is another exampleThere is an RFC standard way of quoting URLs and addresses, namely angle brackets. HN doesn't implement it, though:
<https://gist.github.com/dchest/109180>.
See? The closing > is included in the URL, stupidly.
The convention first appeared in [https://www.ietf.org/rfc/rfc1738.txt] in 1995, with Tim Berners Lee the top author.
That said, it's useful to have features like C escape sequences for control characters or arbitrary characters. That feature should be in the shell language. Someone needed it and hacked it into some version of echo. Others elsewhere didn't and so now it's implementation defined whether or not you get backslash processing.