echo — Write arguments to standard output

echo argument...

Purpose

echo writes its arguments, specified with the argument argument, to standard output. echo accepts these C-style escape sequences:
\a
Bell (accepted but has no effect)
\b
Backspace
\c
Removes any following characters, including \n and \r.
\f
Form feed
\n
Newline
\r
Carriage return
\t
Horizontal tab
\v
Vertical tab
\0num
The byte with the numeric value specified by the zero to three-digit octal num.
\\
Backslash
echo follows the final argument with a newline unless it finds \c in the arguments. Arguments are subject to standard argument manipulation.

Examples

  1. One important use of echo is to expand file names on the command line, as in:
    echo *.[ch]
    This displays the names of all files with names ending in .c or .h—typically C source and include (header) files. echo displays the names on a single line. If there are no file names in the working directory that end in .c or .h, echo simply displays the string *.[ch].

  2. echo is also convenient for passing small amounts of input to a filter or a file:
    echo 'this is\nreal handy' > testfile

Usage Notes

echo is provided as both an external utility and as a shell built-in.

Localization

echo uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_MESSAGES
See Localization for more information.

Exit Values

echo always returns the following exit status value:
0
Successful completion

Portability

POSIX.2, X/Open Portability Guide, UNIX system V.

The POSIX.2 standard does not include escape sequences, so a strictly conforming application cannot use them. printf is suggested as a replacement.

Related Commands

sh