|
|
The echo command prints its argument list, separating each argument with a space, and following the last argument with a newline. For example:
$ echo Hi there!
Hi there!
$
Variables and file specifications are expanded by the shell before
being passed to echo. Consider the following command:
This prints the specified text string before producing a listing of all the files in the current working directory, across the screen.
echo recognizes a number of escape sequences which it expands internally. An escape command is a backslash-escaped character that signifies some other character. The ones recognized by echo are common throughout the shell syntax, as follows:
$ echo The available files are \n *
The available files are
aaaa bbbb cccc dddd eeee
Here, the escape sequence only is quoted. Otherwise, the whole
string can be quoted:
$For example, see the following echo command:foo="a\ty"
$echo $foo
a y $
$ echo "Mary had a little lamb \n \t Its fleece was white as snow"
Mary had a little lamb
\(t1 Its fleece was white as snow
The \n escape causes echo to emit a newline, and the \t
escape causes echo to emit a tab.
You can redirect the output from echo. For example, the who and w commands list the users on your system and the terminals they are logged in on. To send a message to a terminal being used by someone else, you can use a command like the following, if /dev/tty015 is the name of the terminal you want to print a message on:
$ echo Hi there! > /dev/tty015
(Note that this is not the best way to send messages between
terminals;
write(C)
and
talk(TC)
are commands intended for this purpose, and allow two-way
conversation.)