O'Reilly logo

Learning the bash Shell, Second Edition by Bill Rosenblatt, Cameron Newham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

String I/O

Now we’ll zoom back in to the string I/O level and examine the echo and read statements, which give the shell I/O capabilities that are more analogous to those of conventional programming languages.

echo

As we’ve seen countless times in this book, echo simply prints its arguments to standard output. Now we’ll explore the command in greater detail.

Options to echo

echo accepts a few dash options, listed in Table 7.2.

Table 7-2. echo Options

Option Function
-e

Turns on the interpretation of backslash-escaped characters

-E

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

-n

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

echo escape sequences

echo accepts a number of escape sequences that start with a backslash. [89]These are similar to the escape sequences recognized by echo and the C language; they are listed in Table 7.3.

These sequences exhibit fairly predictable behavior, except for \f: on some displays, it causes a screen clear, while on others it causes a line feed. It ejects the page on most printers. \v is somewhat obsolete; it usually causes a line feed.

Table 7-3. echo Escape Sequences

Sequence Character Printed
\a ALERT or CTRL-G (bell)
\b BACKSPACE or CTRL-H
\c Omit final NEWLINE
\E Escape character a
\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

ASCII character with octal (base-8) value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required