Echo (command)
Shell command for writing to standard output
title: "Echo (command)" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["internal-dos-commands", "msx-dos-commands", "os/2-commands", "reactos-commands", "windows-commands", "multics-commands", "standard-unix-programs", "unix-sus2008-utilities", "plan-9-commands", "inferno-(operating-system)-commands", "ibm-i-qshell-commands"] description: "Shell command for writing to standard output" topic_path: "technology/operating-systems" source: "https://en.wikipedia.org/wiki/Echo_(command)" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0
::summary Shell command for writing to standard output ::
::data[format=table title="Infobox software"]
| Field | Value |
|---|---|
| name | echo |
| screenshot | Sleepunix.png |
| caption | The command on Unix |
| author | Douglas McIlroy |
| (AT&T Bell Laboratories) | |
| developer | Various open-source and commercial developers |
| operating system | Multics, Unix, Unix-like, V, Plan 9, Inferno, FLEX, TRIPOS, AmigaDOS, Z80-RIO, OS-9, DOS, MSX-DOS, Panos, FlexOS, SISNE plus, OS/2, Windows, ReactOS, MPE/iX, KolibriOS, SymbOS |
| platform | Cross-platform |
| genre | Command |
| :: |
| name = echo
| logo =
| screenshot = Sleepunix.png
| screenshot size =
| caption = The command on Unix
| author = Douglas McIlroy
(AT&T Bell Laboratories)
| developer = Various open-source and commercial developers
| released =
| latest release version =
| latest release date =
| operating system = Multics, Unix, Unix-like, V, Plan 9, Inferno, FLEX, TRIPOS, AmigaDOS, Z80-RIO, OS-9, DOS, MSX-DOS, Panos, FlexOS, SISNE plus, OS/2, Windows, ReactOS, MPE/iX, KolibriOS, SymbOS
| platform = Cross-platform
| genre = Command
| license =
| website =
echo 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 echo as a builtin command rather than an external application as are many other commands.
Multiple, incompatible implementations of echo 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 -n 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 echo implementations are not compliant in the default environment. Because of these variations, echo is considered a non-portable command and the printf 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:
- Unix and Unix-like shells
- Windows
- Multics
- OS/2
- DOS
- TSC FLEX
- MetaComCo TRIPOS
- Zilog Z80-RIO
- OS-9
- Panos
- FlexOS
- ReactOS
- MPE/iX
- KolibriOS
- SymbOS
- EFI shell.
History
echo 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. echo -n in Version 7 replaced prompt, (which behaved like echo but without terminating its output with a line delimiter).
On PWB/UNIX and later Unix System III, echo started expanding C escape sequences such as \n with the notable difference that octal escape sequences were expressed as \0ooo instead of \ooo in C.
Eighth Edition Unix echo only did the escape expansion when passed a -e option, and that behaviour was copied by a few other implementations such as the builtin echo command of Bash or zsh and GNU echo.
On MS-DOS, the command is available in versions 2 and later.
Examples
::code[lang=doscon] C:>echo Hello world Hello world ::
Using ANSI escape code SGR sequences, compatible terminals can print out colored text.
Using a UNIX System III-style implementation:
::code[lang=bash]
BGRED=echo "\033[41m"
FGBLUE=echo "\033[35m"
BGGREEN=echo "\033[42m"
NORMAL=echo "\033[m"
::
Or a Unix Version 8-style implementation (such as Bash when not in Unix-conformance mode):
::code[lang=bash]
BGRED=echo -e "\033[41m"
FGBLUE=echo -e "\033[35m"
BGGREEN=echo -e "\033[42m"
NORMAL=echo -e "\033[m"
::
and after:
::code[lang=bash] echo "${FGBLUE} Text in blue ${NORMAL}" echo "Text normal" echo "${BGRED} Background in red" echo "${BGGREEN} Background in Green and back to Normal ${NORMAL}" ::
Portably with printf:
::code[lang=bash]
BGRED=printf '\33[41m'
NORMAL=printf '\33[m'
printf '%s\n' "${BGRED}Text on red background${NORMAL}"
::
References
References
- {{man. cu. echo. SUS. write arguments to standard output
- "echo and printf behaviour".
- "8th Edition Unix echo man page".
- "Autoconf documentation on echo portability". Free Software Foundation.
- (2003). "Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition". [[Microsoft Press]].
- "OS/2 Batch File Commands".
- "FlexOS™ User's Guide".
- "Manual".
- "Z80-RIO OPERATING SYSTEM USER'S MANUAL".
- Paul S. Dayan. (1992). "The OS-9 Guru - 1 : The Facts". Galactic Industrial Limited.
- (1987). "A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986".
- (September 12, 1988). "AmigaDOS quick reference". Grand Rapids, Mi : Abacus.
- "Chris's Acorns: Panos".
- (2 October 2023). "echo".
- "FLEX 9.0 User's Manual".
- "MPE/iX Command Reference Manual".
- (3 January 2022). "reactos/reactos".
- "Shell - KolibriOS wiki".
- "Multics Commands".
::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::