echo — Write arguments to standard output

Format

echo argument …

tcsh shell: echo [-n] word …

Description

echo writes its arguments, specified with the argument argument, to standard output. echo accepts these C-style escape sequences:
\a
Bell
\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.

In the tcsh shell, echo writes each word to the shell's standard output, separated by spaces and terminated with a newline.

tcsh echo accepts these C-style escape sequences:
\a
Bell
\b
Backspace
\e
Escape
\f
Form feed
\n
Newline
\r
Carriage return
\t
Horizontal tab
\v
Vertical tab
\nnn
The EBCDIC character corresponding to the octal number nnn

For more information, see tcsh — Invoke a C shell.

Examples

  1. One important use of echo is to expand filenames 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 filenames 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 a built-in shell command.

Localization

echo uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_MESSAGES
  • LC_SYNTAX
  • NLSPATH

See Localization for more information.

Exit value

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

Portability

POSIX.2, UNIX System V.

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

Related information

sh, tcsh