Solaris and echo

OK, most UNIX programmers are familiar with the echo command. It just takes input and writes it back out again – pretty simple, right? WRONG. Solaris has at least one shell, it seems, that has a version of echo with epic bugs. For instance, here’s what it does when you give it the -n flag, which tells it not to print a newline after echoing the input:

$ echo -n "I love Solaris"
-n I love Solaris
$

Yes, instead of either ignoring the -n flag, or even throwing an unrecognized option error, it echos the flag to the screen! This is quite possibly the worst behavior I’ve ever seen in a core UNIX utility. Also, notice that it printed a newline, like I asked it not to? That broke autoconf, since my version number in my AC_INIT call ended up with a newline in it, and strings with random newlines in them don’t compile too well in C…

I also found yet another bug in Solaris echo just Googling out of curiosity. Turns out that the -e flag is also unsupported! Whoever is responsible for maintaining this code, can you please bring it up current with early 1990’s echo functionality? Thank you.


2 thoughts on “Solaris and echo

  1. Tim Foster

    I’m presuming this is intentional for backwards compatibility, and is documented in the 3rd paragraph of echo(1). Run bash or csh and you’ll get shell builtins for the -n option. Otherwise put /usr/ucb in your path and run that version of echo.

    There are modern shells in Solaris, you just need to use them. As for autoconf, well …

  2. Erik Post author

    I’m sure you’re right about backwards compatibility, but if you’re dependent on echo spitting a -n back at you, you have crap code anyway. They should just make /bin/sh into a real shell (like Ubuntu did with dash). Here’s some interesting notes on Ubuntu’s change of /bin/sh from bash to dash:

    https://wiki.ubuntu.com/DashAsBinSh

    They omitted -e, which they actually justify pretty well with the printf argument. BUT, they left -n, since it’s useful. One could get away using printf all the time, but it’s a lot more cumbersome than echo.

    Also, autoconf admittedly sucks, but I have a rather large project that I don’t feel like gutting for a new build system, especially since Solaris is the only place it ever has issues.

    Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *