Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

echo (command)

From Wikipedia, the free encyclopedia
Shell command for writing to standard output
For other uses, seeEcho (disambiguation).
echo
Theecho command onUnix
Original authorsDouglas McIlroy
(AT&T Bell Laboratories)
DevelopersVariousopen-source andcommercial 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

echo is ashellcommand that writes input text tostandard output. It is available in manyoperating system andshells. It is often used in ashell script tolog status, provide feedback to the user and fordebugging. For an interactive session, output by default displays on theterminal screen, but output can bere-directed to afile orpiped to another process.[1]

Many shells implementecho as abuiltin command rather than an externalapplication as are many other commands.

Multiple, incompatible implementations ofecho exist in different shells. Some expand escape sequences by default, and some do not. Some accept options, and some do not. ThePOSIX specification[2] 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, manyecho implementations are not compliant in the default environment. Because of these variations,echo is considered a non-portable command[3] and theprintf command (introduced in Ninth Edition Unix) is preferred instead.

Implementations

[edit]

The command is available the following shells or at least one shell of a listed operating system:

History

[edit]

echo began withinMultics. After it was programmed inC byDoug McIlroy as a "finger exercise" and proved to be useful, it became part ofVersion 2 Unix.echo -n inVersion 7 replacedprompt, (which behaved likeecho but without terminating its output with a line delimiter).[17]

OnPWB/UNIX and laterUnix System III,echo started expandingC 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 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 ofBash orzsh and GNUecho.

OnMS-DOS, the command is available in versions 2 and later.[20]

Examples

[edit]
C:\>echo Hello worldHello world

UsingANSI escape codeSGR sequences, 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

[edit]

References

[edit]
  1. ^Rügheimer, Hannes; Spanik, Christian (September 12, 1988).AmigaDOS quick reference. Grand Rapids, Mi : Abacus.ISBN 9781557550491 – via Internet Archive.
  2. ^echo: write arguments to standard output – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Group
  3. ^"Autoconf documentation on echo portability". Free Software Foundation.Archived from the original on 10 December 2019. Retrieved24 July 2016.
  4. ^"echo".docs.microsoft.com. 2 October 2023.Archived from the original on 11 September 2018. Retrieved8 April 2019.
  5. ^"Multics Commands".www.multicians.org.Archived from the original on 2000-08-16. Retrieved2019-04-19.
  6. ^"OS/2 Batch File Commands". Archived fromthe original on 2019-04-14.
  7. ^"FLEX 9.0 User's Manual"(PDF).Archived(PDF) from the original on 2021-07-25. Retrieved2019-07-04.
  8. ^"Manual"(PDF).www.pagetable.com.Archived(PDF) from the original on 2020-10-21. Retrieved2020-09-12.
  9. ^"Z80-RIO OPERATING SYSTEM USER'S MANUAL"(PDF). Archived fromthe original(PDF) on 2022-01-28. Retrieved2019-05-04.
  10. ^Paul S. Dayan (1992).The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited.ISBN 0-9519228-0-7.
  11. ^"Chris's Acorns: Panos".chrisacorns.computinghistory.org.uk.Archived from the original on 2016-03-31. Retrieved2019-04-08.
  12. ^"FlexOS™ User's Guide"(PDF). Archived fromthe original(PDF) on 2018-09-14.
  13. ^"reactos/reactos".GitHub. 3 January 2022.Archived from the original on 11 December 2017. Retrieved9 June 2019.
  14. ^"MPE/iX Command Reference Manual"(PDF). Archived fromthe original(PDF) on 2018-10-21. Retrieved2018-10-21.
  15. ^"Shell - KolibriOS wiki".wiki.kolibrios.org.Archived from the original on 2019-02-11. Retrieved2018-09-24.
  16. ^"EFI Shells and Scripting".Intel.Archived from the original on 2013-09-27. Retrieved2013-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".Archived from the original on 1 November 2022. Retrieved24 July 2016.
  19. ^"8th Edition Unix echo man page".Archived from the original on 14 November 2017. Retrieved24 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.

Further reading

[edit]

External links

[edit]
Wikibooks has a book on the topic of:Guide to Windows Commands
The WikibookGuide to Unix has a page on the topic of:Commands
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Processes
User environment
Text processing
Shell builtins
Networking
Searching
Software development
Miscellaneous
File system
Text utilities
Shell utilities
Ecosystem
Interpreters
Terminals
File system navigation
File management
Archiving
Disk management
Processes
Registry
User environment
File contents
Scripting
Networking
Maintenance and care
Boot management
Software development
Miscellaneous
Retrieved from "https://en.wikipedia.org/w/index.php?title=Echo_(command)&oldid=1337662193"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp