[go: nahoru, domu]

Jump to content

Echo (command): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
list syntax, organising references
Line 18: Line 18:
| website =
| website =
}}
}}
In [[computing]], '''<code>echo</code>''' is a [[command (computing)|command]] that outputs the strings it is being passed as [[command-line argument|arguments]]. It is a command available in various [[operating system]] [[shell (computing)|shells]] and typically used in [[shell script]]s and [[batch file]]s to output status text to the screen<ref>{{Cite web|url=http://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|via=Internet Archive}}</ref> or a [[computer file]], or as a source part of a [[Pipeline (Unix)|pipeline]].
In [[computing]], '''<code>echo</code>''' is a [[command (computing)|command]] that outputs the strings that are passed to it as [[command-line argument|arguments]]. It is a command available in various [[operating system]] [[shell (computing)|shells]] and typically used in [[shell script]]s and [[batch file]]s to output status text to the screen<ref name="rugheimer-spanik-amigados" /> or a [[computer file]], or as a source part of a [[Pipeline (Unix)|pipeline]].


==Implementations==
==Implementations==
The command is available in the following operating systems:
The command is available in [[Multics]],<ref>{{Cite web|url=https://www.multicians.org/multics-commands.html|title=Multics Commands|website=www.multicians.org}}</ref> [[Technical Systems Consultants|TSC]] [[FLEX (operating system)|FLEX]],<ref>{{Cite web|url=http://www.flexusergroup.com/flexusergroup/pdfs/swflexum.pdf|title=FLEX 9.0 User's Manual}}</ref> [[MetaComCo]] [[TRIPOS]],<ref>{{cite web |url=https://www.pagetable.com/docs/amigados_tripos/tripos_manuals.pdf |title= Manual |website=www.pagetable.com|access-date=2020-09-12}}</ref> [[Zilog]] [[Z80-RIO]],<ref>[https://www.z80cpu.eu/mirrors/oldcomputers.dyndns.org/public/pub/rechner/zilog/zds/z80-rio_os_userman.pdf Z80-RIO OPERATING SYSTEM USER'S MANUAL]</ref> [[Microware]] [[OS-9]],<ref>{{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> [[DOS]], [[Acorn Computers]] [[Panos (operating system)|Panos]],<ref>{{Cite web|url=http://chrisacorns.computinghistory.org.uk/Panos.html#CL|title=Chris's Acorns: Panos|website=chrisacorns.computinghistory.org.uk}}</ref> [[Digital Research]] [[FlexOS]],<ref>[http://www.bitsavers.org/pdf/digitalResearch/flexos/1073-2003_FlexOS_Users_Guide_V1.3_Nov86.pdf]{{dead link|date=September 2020}}</ref> [[IBM]] [[OS/2]],<ref>[http://www.jatomes.com/Help/Os2Bat.php#ECHO]{{dead link|date=September 2020}}</ref> [[Microsoft Windows]],<ref>{{Cite web|url=https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/echo|title=echo|website=docs.microsoft.com}}</ref> [[ReactOS]],<ref>{{Cite web|url=https://github.com/reactos/reactos|title=reactos/reactos|website=GitHub}}</ref> [[Hewlett-Packard|HP]] [[HP Multi-Programming Executive|MPE/iX]],<ref>[http://www.teamnaconsulting.com/compresources/pdfs/c01687363.pdf MPE/iX Command Reference Manual]</ref> [[KolibriOS]],<ref>{{Cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org}}</ref> [[SymbOS]], [[Unix]] and [[Unix-like]] operating systems.
* [[Multics]]<ref name="multics" />
* [[Technical Systems Consultants|TSC]] [[FLEX (operating system)|FLEX]]<ref name="flexusergroup" />
* [[MetaComCo]] [[TRIPOS]]<ref name="tripos" />
* [[Zilog]] [[Z80-RIO]]<ref name="z80 user guide" />
* [[Microware]] [[OS-9]]<ref name="os-9 guru" />
* [[DOS]]
* [[Acorn Computers]] [[Panos (operating system)|Panos]]<ref name="computinghistory" />
* [[Digital Research]] [[FlexOS]]<ref name="flexos user guide" />
* [[IBM]] [[OS/2]]<ref name="jatomes" />
* [[Microsoft Windows]]<ref name="windows-commands" />
* [[ReactOS]]<ref name="reactos" />
* [[Hewlett-Packard|HP]] [[HP Multi-Programming Executive|MPE/iX]]<ref name="teamnaconsulting" />
* [[KolibriOS]]<ref name="kolibrios" />
* [[SymbOS]]
* [[Unix]] and [[Unix-like]] operating systems


Many shells, including all [[Bourne shell|Bourne]]-like (such as [[Bash (Unix shell)|Bash]]<ref>{{Cite web|url=https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html|title=Bash Builtins (Bash Reference Manual)|website=www.gnu.org}}</ref> or [[zsh]]<ref>{{Cite web|url=http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html|title=zsh: 17 Shell Builtin Commands|website=zsh.sourceforge.net}}</ref>) and [[C shell|Csh]]-like shells as well as [[COMMAND.COM]] and [[cmd.exe]] implement <code>echo</code> as a [[shell builtin|builtin command]].
Many shells, including all [[Bourne shell|Bourne]]-like (such as [[Bash (Unix shell)|Bash]]<ref name="Bash-Builtins" /> or [[zsh]]<ref name="zsh echo" />) and [[C shell|Csh]]-like shells as well as [[COMMAND.COM]] and [[cmd.exe]] implement <code>echo</code> as a [[shell builtin|builtin command]].


The command is also available in the [[Unified Extensible Firmware Interface|EFI shell]].<ref name="EFI-Shells-and-Scripting">{{cite web
The command is also available in the [[Unified Extensible Firmware Interface|EFI shell]].<ref name="EFI-Shells-and-Scripting" />
| url = http://software.intel.com/en-us/articles/efi-shells-and-scripting/
| title = EFI Shells and Scripting
| publisher = [[Intel]]
| access-date = 2013-09-25
}}</ref>


==History==
==History==
<code>echo</code> began within [[Multics]]. After it was programmed in [[C (programming language)|C]] by [[Douglas McIlroy|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 Unix|Version 7]] replaced <code>prompt</code>, (which behaved like <code>echo</code> but without terminating its output with a line delimiter).<ref name="reader">{{cite techreport |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>
<code>echo</code> began within [[Multics]]. After it was programmed in [[C (programming language)|C]] by [[Douglas McIlroy|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 Unix|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 [[Escape sequences in C|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">{{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}}</ref>
On [[PWB/UNIX]] and later [[Unix System III]], <code>echo</code> started expanding [[Escape sequences in C|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" />


[[Research Unix|Eighth Edition Unix]] <code>echo</code> only did the escape expansion when passed a <code>-e</code> option,<ref>{{cite web|title=8th Edition Unix echo man page|url=http://man.cat-v.org/unix_8th/1/echo|access-date=24 July 2016}}</ref> and that behaviour was copied by a few other implementations such as the builtin <code>echo</code> command of [[Bash (Unix shell)|Bash]] or [[zsh]] and GNU <code>echo</code>.
[[Research Unix|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 (Unix shell)|Bash]] or [[zsh]] and GNU <code>echo</code>.


On [[MS-DOS]], the command is available in versions 2 and later.<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>
On [[MS-DOS]], the command is available in versions 2 and later.<ref name="RUNNINGMSDOS" />


Nowadays, several incompatible implementations of <code>echo</code> 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.
Nowadays, several incompatible implementations of <code>echo</code> 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.
Line 45: Line 55:
The [[POSIX]] Specification of <code>echo</code><ref>{{man|cu|echo|SUS|write arguments to standard output}}</ref> leaves the behaviour unspecified if the first argument is <code>-n</code> 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, many <code>echo</code> implementations are not compliant in the default environment.
The [[POSIX]] Specification of <code>echo</code><ref>{{man|cu|echo|SUS|write arguments to standard output}}</ref> leaves the behaviour unspecified if the first argument is <code>-n</code> 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, many <code>echo</code> implementations are not compliant in the default environment.


Because of these variations in behaviour, <code>echo</code> is considered a non-portable command on Unix-like systems<ref>{{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}}</ref> and the [[printf (Unix)|<code>printf</code> command]] (where available, introduced by Ninth Edition Unix) is preferred instead.
Because of these variations in behaviour, <code>echo</code> is considered a non-portable command on Unix-like systems<ref name="echo limitations" /> and the [[printf (Unix)|<code>printf</code> command]] (where available, introduced by Ninth Edition Unix) is preferred instead.


==Usage examples==
==Usage examples==
Line 93: Line 103:


==See also==
==See also==
*[[List of Unix commands]]
* [[List of Unix commands]]
*[[List of DOS commands]]
* [[List of DOS commands]]


==References==
==References==
{{Reflist}}
{{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
}}</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}}</ref>

<ref name="zsh echo">{{Cite web|url=http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html|title=zsh: 17 Shell Builtin Commands|website=zsh.sourceforge.net}}</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}}</ref>

<ref name="Bash-Builtins">{{Cite web|url=https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html|title=Bash Builtins (Bash Reference Manual)|website=www.gnu.org}}</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}}</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">[http://www.jatomes.com/Help/Os2Bat.php#ECHO]{{dead link|date=September 2020}}</ref>

<ref name="flexos user guide">[http://www.bitsavers.org/pdf/digitalResearch/flexos/1073-2003_FlexOS_Users_Guide_V1.3_Nov86.pdf]{{dead link|date=September 2020}}</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}}</ref>

<ref name="z80 user guide">[https://www.z80cpu.eu/mirrors/oldcomputers.dyndns.org/public/pub/rechner/zilog/zds/z80-rio_os_userman.pdf Z80-RIO OPERATING SYSTEM USER'S MANUAL]</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 techreport |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 web|url=http://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|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}}</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}}</ref>

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

<ref name="teamnaconsulting">[http://www.teamnaconsulting.com/compresources/pdfs/c01687363.pdf MPE/iX Command Reference Manual]</ref>

<ref name="reactos">{{Cite web|url=https://github.com/reactos/reactos|title=reactos/reactos|website=GitHub}}</ref>

<ref name="kolibrios">{{Cite web|url=http://wiki.kolibrios.org/wiki/Shell|title=Shell - KolibriOS wiki|website=wiki.kolibrios.org}}</ref>

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


==Further reading==
==Further reading==

Revision as of 07:20, 17 October 2021

echo
Original author(s)Douglas McIlroy
(AT&T Bell Laboratories)
Developer(s)Various open-source and commercial developers
Operating systemMultics, 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
PlatformCross-platform
TypeCommand

In computing, echo is a command that outputs the strings that are passed to it as arguments. It is a command available in various operating system shells and typically used in shell scripts and batch files to output status text to the screen[1] or a computer file, or as a source part of a pipeline.

Implementations

The command is available in the following operating systems:

Many shells, including all Bourne-like (such as Bash[14] or zsh[15]) and Csh-like shells as well as COMMAND.COM and cmd.exe implement echo as a builtin command.

The command is also available in the EFI shell.[16]

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).[17]

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.[18]

Eighth Edition Unix echo only did the escape expansion when passed a -e option,[19] 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.[20]

Nowadays, several incompatible implementations of echo 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.

The POSIX Specification of echo[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, many echo 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 the printf command (where available, introduced by Ninth Edition Unix) is preferred instead.

Usage 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

References

  1. ^ Rügheimer, Hannes; Spanik, Christian (September 12, 1988). "AmigaDOS quick reference". Grand Rapids, Mi : Abacus – via Internet Archive.
  2. ^ "Multics Commands". www.multicians.org.
  3. ^ "FLEX 9.0 User's Manual" (PDF).
  4. ^ "Manual" (PDF). www.pagetable.com. Retrieved 2020-09-12.
  5. ^ Z80-RIO OPERATING SYSTEM USER'S MANUAL
  6. ^ Paul S. Dayan (1992). The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited. ISBN 0-9519228-0-7.
  7. ^ "Chris's Acorns: Panos". chrisacorns.computinghistory.org.uk.
  8. ^ [1][dead link]
  9. ^ [2][dead link]
  10. ^ "echo". docs.microsoft.com.
  11. ^ "reactos/reactos". GitHub.
  12. ^ MPE/iX Command Reference Manual
  13. ^ "Shell - KolibriOS wiki". wiki.kolibrios.org.
  14. ^ "Bash Builtins (Bash Reference Manual)". www.gnu.org.
  15. ^ "zsh: 17 Shell Builtin Commands". zsh.sourceforge.net.
  16. ^ "EFI Shells and Scripting". Intel. Retrieved 2013-09-25.
  17. ^ McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139.
  18. ^ Mascheck, Sven. "echo and printf behaviour". Retrieved 24 July 2016.
  19. ^ "8th Edition Unix echo man page". Retrieved 24 July 2016.
  20. ^ Wolverton, Van (2003). Running MS-DOS Version 6.22 (20th Anniversary Edition), 6th Revised edition. Microsoft Press. ISBN 0-7356-1812-7.
  21. ^ echo: write arguments to standard output – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group
  22. ^ "Autoconf documentation on echo portability". Free Software Foundation. Retrieved 24 July 2016.

Further reading