echo [-neE] [arg ...]
echo outputs it's args to stdout, separated by spaces, followed by a newline. The return status is always
0. If the shopt option
xpg_echo is set, Bash dynamically determines whether echo should expand escape characters (listed below) by default based on the current platform.
echo doesn't interpret
-- as the end of options, and will simply print this string if given.
| ||The trailing newline is suppressed.|
| ||Interpretation of the following backslash-escaped characters (below) is enabled.|
| ||Disables the interpretation of these escape characters, even on systems where they are interpreted by default.|
| ||alert (bell)|
| ||suppress further output|
| ||an escape character|
| ||form feed|
| ||new line|
| ||carriage return|
| ||horizontal tab|
| ||vertical tab|
| ||the eight-bit character whose value is the octal value nnn (zero to three octal digits)|
| ||the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)|
| ||the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHH (one to four hex digits)|
| ||the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHHHHHH (one to eight hex digits)|
echois a portability train wreck. No major shell follows POSIX completely, and any shell that attempts to do so should be considered horribly broken. SUSv4 specifies that
echoshall not include any options. Further, it specifies that the behavior of
-nas a first argument shall be determined by the implementation, unless XSI is followed, in which case
-nis always treated as a string, and backslash escapes are interpreted by default.
dashhas the misfeature of following this and interpreting escapes by default, but includes a
-nfeature for suppressing newlines nevertheless.
echowhen used in simple cases is generally reliable. For example, in the very common situation in which echo is supplied with a single argument and whose output is to have a newline appended, using
echois considered common practice.
echo! Ever! Any time you feel tempted to use
-n, or any other special feature of echo, use printf instead! If portability is a requirement, you should consider using
printfexclusively and just ignore that
echoeven exists. If you must use
echo -eand refuse to use
printf, it is usually acceptable to use
echo $'…'if targeting only shells that support this special quoting style.
ksh93should be preferred over
echo. printf still includes most of the functionality of both, and should usually be the most preferred option.