Echo (command)
Template:Short description
Template:Otheruses
Template:Lowercase
{{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other{{#invoke:Check for conflicting parameters|check
| template = Template:Infobox software
| cat = Template:Main other
| logo size; logo_size
| logo class; logo_class
| logo alt; logo_alt
| logo title; logo_title
| logo caption; logo_caption
| screenshot size; screenshot_size
| screenshot upright; screenshot_upright
| screenshot class; screenshot_class
| screenshot alt; screenshot_alt
| screenshot title; screenshot title
| latest release version; latest_release_version
| latest release date; latest_release_date
| latest preview version; latest_preview_version
| latest preview date; latest_preview_date
| latest release version; latest_release_version
| latest release date; latest_release_date
| latest preview version; latest_preview_version
| latest preview date; latest_preview_date
| programming language; programming_language
| operating system; operating_system
}}
echo 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.[1]
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, and some do not. Some accept options, and some do not. The POSIX 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, many echo implementations are not compliant in the default environment. Because of these variations, echo is considered a non-portable command[3] 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:
- Unix and Unix-like shells
- Windows[4]
- Multics[5]
- OS/2[6]
- DOS
- TSC FLEX[7]
- MetaComCo TRIPOS[8]
- Zilog Z80-RIO[9]
- OS-9[10]
- Panos[11]
- FlexOS[12]
- ReactOS[13]
- MPE/iX[14]
- KolibriOS[15]
- SymbOS
- 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]
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 printf:
<syntaxhighlight lang="bash"> BGRED=`printf '\33[41m'` NORMAL=`printf '\33[m'` printf '%s\n' "${BGRED}Text on red background${NORMAL}" </syntaxhighlight>
See also
References
Further reading
External links
Template:Sister project Template:Sister project
Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands Template:Windows commands
- ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedrugheimer-spanik-amigados - ↑ Template:Man
- ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedecho limitations - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedwindows-commands - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedmultics - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedjatomes - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedflexusergroup - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedtripos - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedz80 user guide - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedos-9 guru - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedcomputinghistory - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedflexos user guide - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedreactos - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedteamnaconsulting - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedkolibrios - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedEFI-Shells-and-Scripting - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedreader - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedmascheck-echo - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedman echo - ↑ Cite error: Invalid
<ref>tag; no text was provided for refs namedRUNNINGMSDOS