NAME
echo
—
output arguments
SYNOPSIS
echo |
[-n ] [string]… |
DESCRIPTION
Writes each string, separated by a single space (‘ ’, 0x20), to the standard output stream.
If -n
is specified as the first argument,
it's skipped. Otherwise, the newline character is written after all
strings.
EXIT STATUS
0 if no errors (like the output exceeding its quota) were encountered while writing, otherwise 1 and a diagnostic is issued.
SEE ALSO
STANDARDS
Conforms to IEEE Std 1003.1-2024
(“POSIX.1”); backslashes in strings and
first-argument -n
are implementation-defined
— this implementation handles them compatibly with
Version 7 AT&T UNIX.
HISTORY
Appeared, fully-formed, in the second edition of the UNIX Programmer's Manual as echo(I):
NAME
echo -- echo arguments
SYNOPSIS
echo [ arg1 ... ]
DESCRIPTION
echo writes all its arguments in order as a line on the standard output file.
It is mainly useful for producing diagnostics in command files.
OWNER
doug
Version 4 AT&T UNIX notes that
echo
, which does yield and empty line for no
arguments, but always adds a space after each argument. Either way, it's
impossible to verify any-more.
Version 5 AT&T UNIX sees a C implementation, and a removal of that BUGS stanza — the arguments are separated by single spaces and end with a newline.
Version 7 AT&T UNIX adds
newline-suppressing first-argument--n
behaviour.
This is inherited by 3BSD, and remains unchanged in
the BSD.
Programmer's Workbench (PWB/UNIX), derived from Version 6 AT&T UNIX, additionally sees ‘\n’, ‘\c’ which "terminates echo without a newline", and ‘\0N’, writing the "octal number N".
CB-UNIX 2.1 additionally recognises ‘\b’, ‘\f’, ‘\r’, ‘\t’, ‘\\’, and phrases the octal escape as ‘\n’, described as "the 8-bit character whose ASCII code is the 1-, 2- or 3-digit octal number n, which must start with a zero"; this is the same as the PWB/UNIX one, but just more confusing.
It also notes that if the final argument ends with a space, that space, as well as the terminating newline, is removed — this is described as equivalent to \c, but \c just exit(2)s.
CB-UNIX was, among others, the basis for AT&T
System III UNIX, where it first saw light outside of AT&T.
It sees the same echo
, except that the final-space
behaviour is nowhere to be found.
AT&T System V Release 2 UNIX also recognises ‘\v’.
AT&T System V Release 4
UNIX handles -n
as the first argument, which
replaces the final newline with a space.
AT&T System V Release 2
UNIX and AT&T System V Release 3
UNIX both provide echo
sh(1) built-ins, equivalent to their stand-alone
echo
s (under CB-UNIX, the built-in is
fecho
, and "its output cannot be redirected as
easily as that of echo").
AT&T System V Release 4
UNIX also ships Version 7 AT&T
UNIX echo
under
/usr/ucb. Its built-in depends on
ucb_builtins:
/* * The following flag is set to true if /usr/ucb is found in the path * before /usr/bin. This value is checked when exectuing the echo and test * built-in commands. If true, the command behaves as in BSD systems. */
echo
, otherwise the AT&T
System V Release 3 UNIX built-in
except
on i386, where it also handles -n
-as-first-argument,
but doesn't leave a trailing space (like Version 7
AT&T UNIX, unlike AT&T System V
Release 4 UNIX).
X/Open Portability Guide Issue 2
(“XPG2”) standardises AT&T
System V Release 3 UNIX echo
verbatim. As the two major implementations were irreconcilable,
IEEE Std 1003.2-1992 (“POSIX.2”)
standardised the most base-line Version 2 AT&T
UNIX-style echo
, and specifies
implementation-defined behaviour if any of the strings
contain a ‘\’ or if the first argument is
-n
, instead creating
printf(1) as a portable alternative, with %b
mirrorring AT&T System V Release 3
UNIX escape handling.