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; some do not; some accept options; 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:
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 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 builtin echo command of Bash or zsh and GNU echo.
On MS-DOS, the command is available in versions 2 and later.[20]
Examples
C:\>echo Hello world
Hello world
Using ANSI escape codeSGR sequences, compatible terminals can print out colored text.
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}"