{{Short description|Shell command for writing to standard output}} {{otheruses|Echo (disambiguation)}} {{lowercase}} {{Infobox software | name = echo | logo = | screenshot = Sleepunix.png | screenshot size = | caption = The {{code|echo}} command on Unix | author = Douglas McIlroy<br />(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 = }} '''<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.<ref name="rugheimer-spanik-amigados" />

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<ref>{{man|cu|echo|SUS|write arguments to standard output}}</ref> 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<ref name="echo limitations" /> 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: * Unix and Unix-like shells * Windows<ref name="windows-commands" /> * Multics<ref name="multics" /> * OS/2<ref name="jatomes" /> * DOS * TSC FLEX<ref name="flexusergroup" /> * MetaComCo TRIPOS<ref name="tripos" /> * Zilog Z80-RIO<ref name="z80 user guide" /> * OS-9<ref name="os-9 guru" /> * Panos<ref name="computinghistory" /> * FlexOS<ref name="flexos user guide" /> * ReactOS<ref name="reactos" /> * MPE/iX<ref name="teamnaconsulting" /> * KolibriOS<ref name="kolibrios" /> * SymbOS * EFI shell.<ref name="EFI-Shells-and-Scripting" />

==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).<ref name="reader" />

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.<ref name="mascheck-echo" />

Eighth Edition Unix <code>echo</code> only did the escape expansion when passed a <code>-e</code> option,<ref name="man echo" /> 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.<ref name="RUNNINGMSDOS" />

==Examples== <syntaxhighlight lang="doscon"> C:\>echo Hello world Hello world </syntaxhighlight>

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

Using a UNIX System III-style implementation:

<syntaxhighlight lang="bash"> BGRED=`echo "\033[41m"` FGBLUE=`echo "\033[35m"` BGGREEN=`echo "\033[42m"` NORMAL=`echo "\033[m"` </syntaxhighlight>

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

<syntaxhighlight lang="bash"> BGRED=`echo -e "\033[41m"` FGBLUE=`echo -e "\033[35m"` BGGREEN=`echo -e "\033[42m"` NORMAL=`echo -e "\033[m"` </syntaxhighlight>

and after:

<syntaxhighlight 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}" </syntaxhighlight>

Portably with <code>printf</code>:

<syntaxhighlight lang="bash"> BGRED=`printf '\33[41m'` NORMAL=`printf '\33[m'` printf '%s\n' "${BGRED}Text on red background${NORMAL}" </syntaxhighlight>

==See also== * {{Annotated link|List of DOS commands}} * {{Annotated link|List of POSIX commands}}

==References== {{Reflist|refs= <ref name="EFI-Shells-and-Scripting">{{cite web | url = http://software.intel.com/en-us/articles/efi-shells-and-scripting/ | title = EFI Shells and Scripting | publisher = Intel | access-date = 2013-09-25 | archive-date = 2013-09-27 | archive-url = https://web.archive.org/web/20130927203229/http://software.intel.com/en-us/articles/efi-shells-and-scripting/ | url-status = live }}</ref>

<ref name="mascheck-echo">{{cite web|last1=Mascheck|first1=Sven|title=echo and printf behaviour|url=http://www.in-ulm.de/~mascheck/various/echo+printf/|access-date=24 July 2016|archive-date=1 November 2022|archive-url=https://web.archive.org/web/20221101202049/https://www.in-ulm.de/~mascheck/various/echo+printf/|url-status=live}}</ref>

<ref name="man echo">{{cite web|title=8th Edition Unix echo man page|url=http://man.cat-v.org/unix_8th/1/echo|access-date=24 July 2016|archive-date=14 November 2017|archive-url=https://web.archive.org/web/20171114050953/http://man.cat-v.org/unix_8th/1/echo|url-status=live}}</ref>

<ref name="echo limitations">{{cite web|title=Autoconf documentation on echo portability|url=https://www.gnu.org/software/autoconf/manual/autoconf-2.66/html_node/Limitations-of-Builtins.html#echo|publisher=Free Software Foundation|access-date=24 July 2016|archive-date=10 December 2019|archive-url=https://web.archive.org/web/20191210054648/https://www.gnu.org/software/autoconf/manual/autoconf-2.66/html_node/Limitations-of-Builtins.html#echo|url-status=live}}</ref>

<ref name="RUNNINGMSDOS">{{Cite book|author-last=Wolverton|author-first=Van|title=Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition|date=2003|publisher=Microsoft Press|isbn=0-7356-1812-7}}</ref>

<ref name="jatomes">{{Cite web |url=http://www.jatomes.com/Help/Os2Bat.php |title=OS/2 Batch File Commands |archive-url=https://web.archive.org/web/20190414130026/http://www.jatomes.com/Help/Os2Bat.php |archive-date=2019-04-14 |url-status=dead}}</ref>

<ref name="flexos user guide">{{Cite web |url=http://www.bitsavers.org/pdf/digitalResearch/flexos/1073-2003_FlexOS_Users_Guide_V1.3_Nov86.pdf |title=FlexOS™ User's Guide |archive-url=https://web.archive.org/web/20180914132130/http://www.bitsavers.org/pdf/digitalResearch/flexos/1073-2003_FlexOS_Users_Guide_V1.3_Nov86.pdf |archive-date=2018-09-14 |url-status=dead}}</ref>

<ref name="tripos">{{cite web|url=https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf|title=Manual|website=www.pagetable.com|access-date=2020-09-12|archive-date=2020-10-21|archive-url=https://web.archive.org/web/20201021043218/https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf|url-status=live}}</ref>

<ref name="z80 user guide">{{Cite web |url=https://www.z80cpu.eu/mirrors/oldcomputers.dyndns.org/public/pub/rechner/zilog/zds/z80-rio_os_userman.pdf |title=Z80-RIO OPERATING SYSTEM USER'S MANUAL |access-date=2019-05-04 |archive-date=2022-01-28 |archive-url=https://web.archive.org/web/20220128041146/https://www.z80cpu.eu/mirrors/oldcomputers.dyndns.org/public/pub/rechner/zilog/zds/z80-rio_os_userman.pdf |url-status=dead }}</ref>

<ref name="os-9 guru">{{cite book|author=Paul S. Dayan|year=1992|title=The OS-9 Guru - 1 : The Facts|publisher=Galactic Industrial Limited|isbn=0-9519228-0-7}}</ref>

<ref name="reader">{{cite tech report |first1=M. D. |last1=McIlroy |author-link1=Doug McIlroy |year=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 |series=CSTR |number=139 |institution=Bell Labs}}</ref>

<ref name="rugheimer-spanik-amigados">{{Cite book|url=https://archive.org/details/1988-rugheimer-spanik-amigados-quick-reference|title=AmigaDOS quick reference|first1=Hannes|last1=Rügheimer|first2=Christian|last2=Spanik|date=September 12, 1988|publisher=Grand Rapids, Mi : Abacus|isbn=9781557550491|via=Internet Archive}}</ref>

<ref name="computinghistory">{{Cite web|url=http://chrisacorns.computinghistory.org.uk/Panos.html#CL|title=Chris's Acorns: Panos|website=chrisacorns.computinghistory.org.uk|access-date=2019-04-08|archive-date=2016-03-31|archive-url=https://web.archive.org/web/20160331135522/http://chrisacorns.computinghistory.org.uk/Panos.html#CL|url-status=live}}</ref>

<ref name="windows-commands">{{Cite web|url=https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/echo|title=echo|website=docs.microsoft.com|date=2 October 2023|access-date=8 April 2019|archive-date=11 September 2018|archive-url=https://web.archive.org/web/20180911191929/https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/echo|url-status=live}}</ref>

<ref name="flexusergroup">{{Cite web|url=http://www.flexusergroup.com/flexusergroup/pdfs/swflexum.pdf|title=FLEX 9.0 User's Manual|access-date=2019-07-04|archive-date=2021-07-25|archive-url=https://web.archive.org/web/20210725110201/http://www.flexusergroup.com/flexusergroup/pdfs/swflexum.pdf|url-status=live}}</ref>

<ref name="teamnaconsulting">{{Cite web |url=http://www.teamnaconsulting.com/compresources/pdfs/c01687363.pdf |title=MPE/iX Command Reference Manual |access-date=2018-10-21 |archive-date=2018-10-21 |archive-url=https://web.archive.org/web/20181021232213/http://www.teamnaconsulting.com/compresources/pdfs/c01687363.pdf |url-status=dead }}</ref>

<ref name="reactos">{{Cite web|url=https://github.com/reactos/reactos|title=reactos/reactos|website=GitHub|date=3 January 2022|access-date=9 June 2019|archive-date=11 December 2017|archive-url=https://web.archive.org/web/20171211170155/https://github.com/reactos/reactos|url-status=live}}</ref>

<ref name="kolibrios">{{Cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org|access-date=2018-09-24|archive-date=2019-02-11|archive-url=https://web.archive.org/web/20190211231827/http://wiki.kolibrios.org/wiki/Shell|url-status=live}}</ref>

<ref name="multics">{{Cite web|url=https://www.multicians.org/multics-commands.html|title=Multics Commands|website=www.multicians.org|access-date=2019-04-19|archive-date=2000-08-16|archive-url=https://web.archive.org/web/20000816062325/https://www.multicians.org/multics-commands.html|url-status=live}}</ref> }}

==Further reading== *{{Cite book|author-last=Wolverton|author-first=Van|title=MS-DOS Commands: Microsoft Quick Reference, 4th Revised edition|date=1990|publisher=Microsoft Press|isbn=978-1556152894}} *{{Cite book|author1=Kathy Ivens|author2=Brian Proffit|year=1993|title=OS/2 Inside & Out|publisher=Osborne McGraw-Hill|isbn=978-0078818714}} *{{Cite book|first=Æleen|last=Frisch|year=2001|title=Windows 2000 Commands Pocket Reference|publisher=O'Reilly|isbn=978-0-596-00148-3}}

==External links== {{Wikibooks|Guide to Windows Commands}} {{Wikibooks|Guide to Unix|Commands}} *{{man|cu|echo|SUS|write arguments to standard output}} *{{man|1|echo|Plan 9}} *{{man|1|echo|Inferno}} *[https://technet.microsoft.com/en-us/library/bb490897.aspx Microsoft TechNet Echo article]

{{Unix commands}} {{Plan 9 commands}} {{Core Utilities commands}} {{Windows commands}}

Category:Internal DOS commands Category:MSX-DOS commands Category:OS/2 commands Category:ReactOS commands Category:Windows commands Category:Multics commands Category:Standard Unix programs Category:Unix SUS2008 utilities Category:Plan 9 commands Category:Inferno (operating system) commands Category:IBM i Qshell commands