Previous | Table of Contents | Next |
DESCRIPTION
The internal echo command displays its arguments to your terminal. More precisely, echo writes its arguments on the standard output. The arguments are strings separated by blanks and terminated by a new-line. echo understands the more popular C-like escape character sequences. Some of the features and uses of echo are:
COMMAND FORMAT
Following is the general format of the echo command.
echo [ -n ] [ arg ... ]
Options
The following list describes the options and their arguments that may be used to control how echo functions.
-n | Causes echo not to output a new-line character. Thus the text is displayed and the cursor remains after the last displayed character. For example: |
echo -n "Enter choice: " produces, Enter choice: _ whereas echo "Enter choice: " produces, Enter choice: _
Basically you use the -n for shell script prompt lines. |
The -n is also supported by the ksh print command. So if you have echo as an alias for print - the -n option will work just like on BSD and csh echo .
Arguments
The arguments to echo are whatever text you wish to write to the standard output. If no arguments are specified, then echo displays a blank line by writing a single new-line character. You can use the following list of escape sequence characters to produce special output from echo :
CAUTION:
You must remember that the shell interprets the (backslash) as a special character. Therefore, it is recommended that you place your echo arguments inside double quotes.
\b | produces a backspace on the output. |
\c | writes the output, but does NOT terminate it with a new-line. Must be last. |
\f | produces a form feed. |
\n | produces a new-line. |
\r | produces a carriage return. |
\t | produces a tab. |
\v | produces a vertical tab. |
\\ | produces a backslash. |
\0 n | produces the ASCII character with the octal code of n , where n is a 1-, 2-, or 3-digit octal number representing the desired character. |
|
---|
BSD (Berkeley) |
The BSD and csh versions of echo do not support the escape sequences listed above. |
|
FURTHER DISCUSSION
The following examples show some of the useful aspects of this simple command:
cj echo * # display all files in current directory cj echo *.[ch] # display all files ending with a .c or .h cj echo $TERM # display the value of the TERM variable
DIAGNOSTICS AND BUGS
When you use the \0 n escape sequence you must always precede the n with a 0 (zero). This informs echo that the number is octal.
To use escape sequences you must either enclose them in double quotes, single quotes, or use two \ (backslashes).
If you need to use these escape characters, the octal equivalents can be found in Appendix G.
RELATED COMMANDS
Refer to the print command described in Module 106 and the ksh command described in Module 71.
RELATED FILES
The echo command writes to the standard output. Therefore, you may redirect it to a file or a pipe.
APPLICATIONS
The echo command is used to display text and variables to the user s terminal. Since the standard output is the default, output may be redirected as desired. It is often used to direct known output into a pipe. It is used in shell scripts to display return codes and debugging output. Menus and data entry screens can be built using echo . The select command should also be studied for menu building.
TYPICAL OPERATION
In this activity you use the echo command to display text and variables. You also use it to output new-lines, tabs, and no new-line via escape sequences. Begin at the shell prompt.
|
---|
C Shell |
If you are using the csh , type sh and press Return to enter a Bourne shell for the following examples. Eliminate the -- and escape sequences from the echo commands if present. Replace the \t notation with tabs. |
|
cj echo "