Echo

Henry Spencer henry at utzoo.uucp
Fri Dec 2 07:45:52 AEST 1988


In article <6557 at june.cs.washington.edu> ka at june.cs.washington.edu (Kenneth Almquist) writes:
>I've been implementing a public domain shell and I'm wondering what to
>do about the echo builtin.  The System V echo command interprets a number
>of escape sequences (e.g. \n for newline) which the BSD echo does not...

Arguably the best approach is that taken by the V8 echo, in which the
escape are interpreted only if the -e option is given.  No matter what
you do, you'll have compatibility problems with at least part of your
user community, so the best thing to do is to accept compatibility
problems with all of them and *fix* the problem.  We did.  (We run a
variant of the V8/V9 shell which has echo builtin.)

>1.  Implement the System V echo on the grounds that it will make it easier
>    to run System V shell scripts.

Having the escapes available actually turns out to be surprisingly handy,
or at least that's been our experience.

>2.  Implement the BSD echo on the grounds that it's the "right" approach
>    (since the System V echo is useless if you want to echo an arbitrary
>    string unchanged).

Actually you can't echo an *arbitrary* string with any of the current
echos, since strings like "-n" tend to have surprising effects even in
otherwise-innocuous versions, but that's a lesser problem.

>3.  Don't provide an echo builtin, so users get whatever echo command is
>    installed in /bin.  This follows the principle of least surprise, but
>    it makes shell scripts run slowly and does nothing for portability.

The original V8 shell actually did this.  We put echo back into ours
because the performance impact just wasn't acceptable.  With a fast echo,
the shell makes a superb programming language for applications work.
Without, forget it.  The pragmatic issues outweigh the cleanliness ones
for us on this one.  Mind you, you need to put some non-trivial effort
into making the semantics match those of a separate command *exactly*.

>Any suggestions?  In particular I would like to know if any standards
>organizations have addressed the semantics of echo.  Does anyone know
>what the merged AT&T/SUN UNIX is going to do about echo?

They will presumably go with the SVID approach, although I could be
wrong.  The standard to watch is the POSIX command-level bunch, 1003.2.
I don't know what they've done about echo in particular.
-- 
SunOSish, adj:  requiring      |     Henry Spencer at U of Toronto Zoology
32-bit bug numbers.            | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.unix.wizards mailing list