Automating frequent tasks

The echo command

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:

echo The available files are *

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:

Alert (rings the terminal bell)


No newline at end of echo output

Form feed


Carriage return (no newline)


Vertical tab

Quotes a character with special meaning to the shell. For example, ``\\'' generates a single backslash: as an escape character, the backslash must be escaped or quoted to stop the shell processing it as the prefix to a command.

nnn is an octal number, exactly three digits long, which represents an ASCII character value to insert.
Note that one of the quoting mechanisms must be employed when using escape sequences with the echo command, 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:
   $ foo="a\ty"
   $ echo $foo
   a	y
For example, see the following echo command:
   $ 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.)
Next topic: The print command (Korn shell only)
Previous topic: Sending a message to a terminal

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003