Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

checkout the different implementations of echo across various operating systems: "https://gist.github.com/dchest/1091803".


Do you even know what coreutils is? It is not openbsdutils. It is not plan9utils. It is not even linuxutils. It builds and runs on virtually every deployed vaguely POSIX-ish environment and then some.

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.


I've used the -e option in GNU's echo many times. The various other versions are strictly less useful to me.

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?



I've used -e on GNU's `echo` quite a bit as well. But FreeBSD also supports `printf` (as does Linux by the way), so it's not a great inconvenience the missing -e flag on FreeBSD's `echo`.

    $ 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              example


To delimit URL's, use square brackets: [https://gist.github.com/dchest/109180].

There 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.


As a result, the specification for echo is a ridiculous mess which deviates from the other POSIX utilities. It doesn't have the normal command argument handling, and also has implementation-defined behaviors. It's a good command to avoid in serious scripting, other than for outputting fixed, alphanumeric strings.

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.


Browser seem to include the end quote when clicked. It mush be removed for the url to work.


That link is not working for me, Github is throwing a 404.


The link has an extraneous `"` character at the end. It works fine if you remove it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: