echo Options and Escape Sequences

echo accepts a number of arguments (see Table A-11).

Table A-11. echo options

Options

Function

-e

Turns on the interpretation of backslash-escaped characters

-E

Turns off the interpretation of backslash-escaped characters on systems where this mode is the default

-n

Omits the final newline (same as the \c escape sequence)

echo accepts a number of escape sequences that start with a backslash.

These sequences in Table A-12 exhibit fairly predictable behavior, except for \f, which on some displays causes a screen clear while on others it causes a line feed, and it ejects the page on most printers. \v is somewhat obsolete; it usually causes a line feed.

Table A-12. echo escape sequences

Sequence

Character printed

\a

Alert or Ctrl-G (bell)

\b

Backspace or Ctrl-H

\c

Omit final newline

\e

Escape character (same as \E)

\E

Escape character

\f

Formfeed or Ctrl-L

\n

Newline (not at end of command) or Ctrl-J

\r

Return (Enter) or Ctrl-M

\t

Tab or Ctrl-I

\v

Vertical Tab or Ctrl-K

\n nnn

The eight-bit character whose value is the octal (base-8) value nnn where nnn is 1 to 3 digits

\0 nnn

The eight-bit character whose value is the octal (base-8) value nnn where nnn is 0 to 3 digits

\xHH

The eight-bit character whose value is the hexadecimal (base-16) value HH (one or two digits)

\\

Single backslash

The \n, \0, and \x sequences are even more device-dependent and can be used for complex I/O, such as cursor control and special graphics characters.

Get bash Cookbook 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.