help needed with echo -e, S aed512

John P. Linderman jpl at allegra.UUCP
Sun Oct 14 02:23:48 AEST 1984


You'd think a command that "echos its arguments" would be simple and
unambiguous, but echo is an object lesson in the ability of reasonable
people to differ about "the obvious".  For example, just about everybody
will probably agree that distinct arguments ought to be separated on
output in some way (every echo I know separates them with a single
blank) and that a newline ought to follow the final argument.  But
every implementation I know of has also recognized that it is useful
to be able to suppress the final newline, so prompts can be echoed.
PWB UNIX systems in the early 70's adopted the convention that if the
last two characters of an argument were \c, then the newline (and any
subsequent arguments) would be suppressed.  Berkeley UNIX adopted a
-n flag to suppress the newline.

I confess to being an early corrupter of echo, modifying it to recognize
all the C escapes like \t and \f and \033.  I complained to the forces
then maintaining USG UNIX, and a version that accepted these escapes was
eventually released.  I think the escapes are great, because they make
my shell scripts much more readable.  Other people differ, and don't
make the escapes available.  Berkeley echo is in this camp.  Version 8
UNIX lets you take your pick.  The -e option causes the C escapes to be
processed, its absence echos the arguments without interpretation.
Since S grew up near, if not under, Version 8, I presume the flag means
interpret escape sequences in the arguments.

The good news is that it is very easy to modify echo to process the
escapes.  The bad news is that there are at least three distinct and
incompatible versions of echo in common use, and writing portable
(and readable) shell scripts is dreadfully difficult as a result.

John P. Linderman  Department of Antiquities  allegra!jpl



More information about the Comp.unix.wizards mailing list