ECHO(1) General Commands Manual Fully-rendered PDF

echooutput arguments

echo [-n] [string]…

Writes each string, separated by a single space (‘ ’, ), 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.

0 if no errors (like the output exceeding its quota) were encountered while writing, otherwise and a diagnostic is issued.

printf(1)

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.

Appeared, fully-formed, in the second edition of the UNIX Programmer's Manual as echo(I):

echo [ arg1 ... ]
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.

Version 4 AT&T UNIX notes that

with no arguments does not print a blank line.
in the BUGS section, but this is seemingly incongruent with Version 2 AT&T UNIX 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 ‘’, ‘’, ‘’, ‘’, ‘\\’, 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 ‘’.

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 echos (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.
 */
If set, it uses inlined Version 7 AT&T UNIX echo, otherwise the AT&T System V Release 3 UNIX built-in 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.

July 19, 2024 voreutils 5a9f9f29