echo (command)

{{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
(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 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; some do not; some accept options; some do not. The POSIX specification{{man|cu|echo|SUS|write arguments to standard output}} 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:

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

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:

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):

BGRED=`echo -e "\033[41m"`

FGBLUE=`echo -e "\033[35m"`

BGGREEN=`echo -e "\033[42m"`

NORMAL=`echo -e "\033[m"`

and after:

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:

BGRED=`printf '\33[41m'`

NORMAL=`printf '\33[m'`

printf '%s\n' "${BGRED}Text on red background${NORMAL}"

See also

  • {{Annotated link|List of DOS commands}}
  • {{Annotated link|List of POSIX commands}}

References

{{Reflist|refs=

{{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

}}

{{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}}

{{cite web|title=8th Edition Unix echo man page|url=http://man.cat-v.org/unix_8th/1/echo|access-date=24 July 2016}}

{{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}}

{{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}}

{{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}}

{{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}}

{{cite web |url=https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf |title= Manual |website=www.pagetable.com|access-date=2020-09-12}}

{{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}}

{{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}}

{{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}}

{{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}}

{{Cite web|url=http://chrisacorns.computinghistory.org.uk/Panos.html#CL|title=Chris's Acorns: Panos|website=chrisacorns.computinghistory.org.uk}}

{{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 }}

{{Cite web|url=http://www.flexusergroup.com/flexusergroup/pdfs/swflexum.pdf|title=FLEX 9.0 User's Manual}}

{{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 }}

{{Cite web|url=https://github.com/reactos/reactos|title=reactos/reactos|website=GitHub|date=3 January 2022}}

{{Cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org}}

{{Cite web|url=https://www.multicians.org/multics-commands.html|title=Multics Commands|website=www.multicians.org}}

}}

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}}