Incomputing,echo
is acommandthat outputs the strings that are passed to it asarguments.It is a command available in variousoperating systemshellsand typically used inshell scriptsandbatch filesto output status text to the screen[1]or acomputer file,or as a source part of apipeline.
Implementations
editThe command is available in the following operating systems:
- Multics[2]
- TSCFLEX[3]
- MetaComCoTRIPOS[4]
- ZilogZ80-RIO[5]
- MicrowareOS-9[6]
- DOS
- Acorn ComputersPanos[7]
- Digital ResearchFlexOS[8]
- IBMOS/2[9]
- Microsoft Windows[10]
- ReactOS[11]
- HPMPE/iX[12]
- KolibriOS[13]
- SymbOS
- UnixandUnix-likeoperating systems
Many shells, including allBourne-like (such asBash[14]orzsh[15]) andCsh-like shells as well asCOMMAND.COMandcmd.exeimplementecho
as abuiltin command.
History
editecho
began withinMultics.After it was programmed inCbyDoug McIlroyas a "finger exercise" and proved to be useful, it became part ofVersion 2 Unix.echo -n
inVersion 7replacedprompt
,(which behaved likeecho
but without terminating its output with a line delimiter).[17]
OnPWB/UNIXand laterUnix System III,echo
started expandingC escape sequencessuch as\n
with the notable difference that octal escape sequences were expressed as\0ooo
instead of\ooo
in C.[18]
Eighth Edition Unixecho
only did the escape expansion when passed a-e
option,[19]and that behaviour was copied by a few other implementations such as the builtinecho
command ofBashorzshand GNUecho
.
OnMS-DOS,the command is available in versions 2 and later.[20]
Nowadays, several incompatible implementations ofecho
exist on different operating systems (often several on the same system), some of them expanding escape sequences by default, some of them not, some of them accepting options (the list of which varying with implementations), some of them not.
ThePOSIXspecification ofecho
[21]leaves the behaviour unspecified if the first argument is-n
or any argument contain 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, manyecho
implementations are not compliant in the default environment.
Because of these variations in behaviour,echo
is considered a non-portable command on Unix-like systems[22]and theprintf
command(where available, introduced by Ninth Edition Unix) is preferred instead.
Usage examples
editC:\>echoHello world
Hello world
UsingANSI escape codeSGRsequences, compatible terminals can print out colored text.
Using aUNIX 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 withprintf
:
BGRED=`printf'\33[41m'`
NORMAL=`printf'\33[m'`
printf'%s\n'"${BGRED}Text on red background${NORMAL}"
See also
editReferences
edit- ^Rügheimer, Hannes; Spanik, Christian (September 12, 1988).AmigaDOS quick reference.Grand Rapids, Mi: Abacus.ISBN9781557550491– via Internet Archive.
- ^"Multics Commands".www.multicians.org.
- ^"FLEX 9.0 User's Manual"(PDF).
- ^"Manual"(PDF).www.pagetable.com.Retrieved2020-09-12.
- ^"Z80-RIO OPERATING SYSTEM USER'S MANUAL"(PDF).
- ^Paul S. Dayan (1992).The OS-9 Guru - 1: The Facts.Galactic Industrial Limited.ISBN0-9519228-0-7.
- ^"Chris's Acorns: Panos".chrisacorns.computinghistory.org.uk.
- ^"FlexOS™ User's Guide"(PDF).Archived fromthe original(PDF)on 2018-09-14.
- ^"OS/2 Batch File Commands".Archived fromthe originalon 2019-04-14.
- ^"echo".docs.microsoft.com.2 October 2023.
- ^"reactos/reactos".GitHub.3 January 2022.
- ^"MPE/iX Command Reference Manual"(PDF).Archived fromthe original(PDF)on 2018-10-21.Retrieved2018-10-21.
- ^"Shell - KolibriOS wiki".wiki.kolibrios.org.
- ^"Bash Builtins (Bash Reference Manual)".www.gnu.org.
- ^"zsh: 17 Shell Builtin Commands".zsh.sourceforge.net.
- ^"EFI Shells and Scripting".Intel.Retrieved2013-09-25.
- ^McIlroy, M. D.(1987).A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986(PDF)(Technical report). CSTR. Bell Labs. 139.
- ^Mascheck, Sven."echo and printf behaviour".Retrieved24 July2016.
- ^"8th Edition Unix echo man page".Retrieved24 July2016.
- ^Wolverton, Van (2003).Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition.Microsoft Press.ISBN0-7356-1812-7.
- ^The Single UNIX Specification,Version 4 fromThe Open Group :write arguments to standard output – Shell and Utilities Reference,
- ^"Autoconf documentation on echo portability".Free Software Foundation.Retrieved24 July2016.
Further reading
edit- Wolverton, Van (1990).MS-DOS Commands: Microsoft Quick Reference, 4th Revised edition.Microsoft Press.ISBN978-1556152894.
- Kathy Ivens; Brian Proffit (1993).OS/2 Inside & Out.Osborne McGraw-Hill.ISBN978-0078818714.
- Frisch, Æleen (2001).Windows 2000 Commands Pocket Reference.O'Reilly.ISBN978-0-596-00148-3.
External links
edit- The Single UNIX Specification,Version 4 fromThe Open Group :write arguments to standard output – Shell and Utilities Reference,
- Plan 9Programmer's Manual, Volume 1 –
- InfernoGeneral commandsManual –
- Microsoft TechNet Echo article