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 ... |
Get Learning the bash Shell, Second 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.