预计阅读本页时间:-
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
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
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 characters on systems where this mode is the default
-n
Omits the final newline (same as the \c escape sequence)
echo escape sequences
echo accepts a number of escape sequences that start with a backslash.[2] 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 (same as \E)
\E
Escape character[3]
\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 n, where n is 1 to 3 digits
\0nnn
The eight-bit character whose value is the octal (base-8) value nnn where nnn is 1 to 3 digits
\xHH
The eight-bit character whose value is the hexadecimal (base-16) value HH (one or two digits)
\\
Single backslash
[3] Not available in versions of bash prior to 2.0.
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.