Name

echo

Synopsis

    echo [option] [string]

Echo arguments to standard output . Often used for producing prompts from shell scripts. This is the echo command in the filesystem, not the one built into the shells (see Chapters 4 and 5).

Although echo is conceptually the simplest of all Unix commands, using it in practice is complicated, because of portability and version differences. (Consider using printf instead.) The following sections summarize the differences.

Options

-e

Always interpret escape sequences in argument strings.

-E

Never interpret escape sequences in argument strings.

-n

Do not print the final terminating newline.

Version Differences

Solaris /usr/bin/echo

Does not accept any options. Interprets the escape sequences described next.

Solaris /usr/ucb/echo

Accepts the -n option if it’s first. Does not interpret escape sequences.

Mac OS X /bin/echo

Accepts the -n option if it’s first, and interprets only the \c escape sequence.

GNU/Linux /bin/echo

Accepts the -e, -E, and -n options, and the options --help and --version.

Bourne shell echo

Does not accept the -n option. Interprets the escape sequences described next, except \a.

C shell echo

Accepts the -n option if it’s first. Does not interpret escape sequences. In tcsh, the echo_style shell variable controls emulation of BSD and/or System V echo options and escape sequences.

Korn shell echo

Searches $PATH and behaves like the first version of echo that it finds.

Bash echo

Accepts the -e, -E, and -n options.

Escape Sequences

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.