Echo (command)

Last updated
echo
Original author(s) Douglas McIlroy
(AT&T Bell Laboratories)
Developer(s) Various open-source and commercial developers
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
Type Command

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.

Contents

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

Related Research Articles

<span class="mw-page-title-main">Bash (Unix shell)</span> GNU replacement for the Bourne shell

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used as the default login shell for most Linux distributions. Bash was one of the first programs Linus Torvalds ported to Linux, alongside GCC. A version is also available for Windows 10 and Windows 11 via the Windows Subsystem for Linux. It is also the default user shell in Solaris 11. Bash was also the default shell in versions of Apple macOS from 10.3 to 10.15, which changed the default shell to zsh, although Bash remains available as an alternative shell.

<span class="mw-page-title-main">Shell script</span> Script written for the shell, or command line interpreter, of an operating system

A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script which sets up the environment, runs the program, and does any necessary cleanup or logging, is called a wrapper.

mkdir Directory creation command on various operating systems

The mkdir command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory. It is also available in the EFI shell and in the PHP scripting language. In DOS, OS/2, Windows and ReactOS, the command is often abbreviated to md.

pwd Directory information command on various operating systems

In Unix-like and some other operating systems, the pwd command writes the full pathname of the current working directory to the standard output.

In computing, rmdir is a command which will remove an empty directory on various operating systems.

In computing, touch is a command used to update the access date and/or modification date of a computer file or directory. It is included in Unix and Unix-like operating systems, TSC's FLEX, Digital Research/Novell DR DOS, the AROS shell, the Microware OS-9 shell, and ReactOS. The command is also available for FreeDOS and Microsoft Windows.

The printf family of functions in the C programming language are a set of functions that take a format string as input among a variable sized list of other values and produce as output a string that corresponds to the format specifier and given input values. The string is written in a simple template language: characters are usually copied literally into the function's output, but format specifiers, which start with a % character, indicate the location and method to translate a piece of data to characters. The design has been copied to expose similar functionality in other programming languages.

time (Unix) Command in Unix and Unix-like operating systems

In computing, time is a command in Unix and Unix-like operating systems. It is used to determine the duration of execution of a particular command.

join is a command in Unix and Unix-like operating systems that merges the lines of two sorted text files based on the presence of a common field. It is similar to the join operator used in relational databases but operating on text files.

In computing, kill is a command that is used in several popular operating systems to send signals to running processes.

The Thompson shell was the first Unix shell, introduced in the first version of Unix in 1971, and was written by Ken Thompson. It was a simple command interpreter, not designed for scripting, but nonetheless introduced several innovative features to the command-line interface and led to the development of the later Unix shells.

<span class="mw-page-title-main">Comparison of command shells</span>

A command shell is a command-line interface to interact with and manipulate a computer's operating system.

more (command) Terminal pager available on various operating systems

In computing, more is a command to view the contents of a text file one screen at a time. It is available on Unix and Unix-like systems, DOS, Digital Research FlexOS, IBM/Toshiba 4690 OS, IBM OS/2, Microsoft Windows and ReactOS. Programs of this sort are called pagers. more is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.

In computing, tee is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.

ren (command)

In computing, ren is a command in various command-line interpreters (shells) such as COMMAND.COM, cmd.exe, 4DOS, 4NT and Windows PowerShell. It is used to rename computer files and in some implementations also directories. It is analogous to the Unix mv command. However, unlike mv, ren cannot be used to move files, as a new directory for the destination file may not be used. Alternatively, move may be used if available. On versions of MS-DOS that do not support the move command, the user would simply copy the file to a new destination, and then delete the original file. A notable exception to this rule is DOSBox, in which ren may be used to move a file, since move is not supported.

In computing, pushd and popd are commands used to work with the command line directory stack. They are available on command-line interpreters such as 4DOS, Bash, C shell, tcsh, Hamilton C shell, KornShell, cmd.exe, and PowerShell for operating systems such as Windows and Unix-like systems.

find (Windows)

In computing, find is a command in the command-line interpreters (shells) of a number of operating systems. It is used to search for a specific text string in a file or files. The command sends the specified lines to the standard output device.

help (command) Command in various command line shells

In computing, help is a command in various command line shells such as COMMAND.COM, cmd.exe, Bash, qshell, 4DOS/4NT, Windows PowerShell, Singularity shell, Python, MATLAB and GNU Octave. It provides online information about available commands and the shell environment.

getopts is a built-in Unix shell command for parsing command-line arguments. It is designed to process command line arguments that follow the POSIX Utility Syntax Guidelines, based on the C interface of getopt.

<span class="mw-page-title-main">Command-line interface</span> Computer interface that uses text

A command-line interface (CLI) is a means of interacting with a computer program by inputting lines of text called command-lines. Command-line interfaces emerged in the mid-1960s, on computer terminals, as a user-friendly alternative to punched cards.

References

  1. Rügheimer, Hannes; Spanik, Christian (September 12, 1988). AmigaDOS quick reference. Grand Rapids, Mi : Abacus. ISBN   9781557550491 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" (PDF).
  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. "FlexOS™ User's Guide" (PDF). Archived from the original (PDF) on 2018-09-14.
  9. "OS/2 Batch File Commands". Archived from the original on 2019-04-14.
  10. "echo". docs.microsoft.com. 2 October 2023.
  11. "reactos/reactos". GitHub. 3 January 2022.
  12. "MPE/iX Command Reference Manual" (PDF). Archived from the original (PDF) on 2018-10-21. Retrieved 2018-10-21.
  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