Skip to Content
Learning the bash Shell, Second Edition
book

Learning the bash Shell, Second Edition

by Cameron Newham, Bill Rosenblatt
January 1998
Beginner
336 pages
10h 6m
English
O'Reilly Media, Inc.
Content preview from Learning the bash Shell, Second Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning the bash Shell, 3rd Edition

Learning the bash Shell, 3rd Edition

Cameron Newham

Publisher Resources

ISBN: 1565923472Catalog PageErrata