my-server
← Wiki Redirected from Echo (EFI command)

Echo (command)

<code>echo</code> is a shell command that writes input text to standard output. It is available in many operating system and shells. It is often used in a shell script to log status, provide feedback to the user and for debugging. For an interactive session, output by default displays on the terminal screen, but output can be re-directed to a file or piped to another process.

Many shells implement <code>echo</code> as a builtin command rather than an external application as are many other commands.

Multiple, incompatible implementations of <code>echo</code> exist in different shells. Some expand escape sequences by default, and some do not. Some accept options, and some do not. The POSIX specification leaves the behavior unspecified if the first argument is <code>-n</code> or any argument contains backslash characters while the Unix specification (XSI option in POSIX) mandates the expansion of some sequences and does not allow any option processing. In practice, many <code>echo</code> implementations are not compliant in the default environment. Because of these variations, <code>echo</code> is considered a non-portable command and the <code>printf</code> command (introduced in Ninth Edition Unix) is preferred instead.

Implementations

The command is available the following shells or at least one shell of a listed operating system:

History

<code>echo</code> began within Multics. After it was programmed in C by Doug McIlroy as a "finger exercise" and proved to be useful, it became part of Version 2 Unix. <code>echo -n</code> in Version 7 replaced <code>prompt</code>, (which behaved like <code>echo</code> but without terminating its output with a line delimiter).

On PWB/UNIX and later Unix System III, <code>echo</code> started expanding C escape sequences such as <code>\n</code> with the notable difference that octal escape sequences were expressed as <code>\0ooo</code> instead of <code>\ooo</code> in C.

Eighth Edition Unix <code>echo</code> only did the escape expansion when passed a <code>-e</code> option, and that behaviour was copied by a few other implementations such as the builtin <code>echo</code> command of Bash or zsh and GNU <code>echo</code>.

On MS-DOS, the command is available in versions 2 and later.

Examples

Using ANSI escape code SGR sequences, compatible terminals can print out colored text.

Using a UNIX System III-style implementation:

Or a Unix Version 8-style implementation (such as Bash when not in Unix-conformance mode):

and after:

Portably with <code>printf</code>:

See also

References

Further reading

External links