|
|
echo is useful for producing diagnostics in command files, for sending known data into a pipe, and for displaying the contents of environment variables.
The C shell, the Korn shell, and the Bourne shell each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. See shell_builtins.1 sh's echo, ksh's echo, and /usr/bin/echo understand the black-slashed escape characters, except that sh's echo does not understand \a as the alert character; however, these commands do not have a -n option. csh's echo and /usr/ucb/echo, on the other hand, have a -n option, but do not understand the back-slashed escape characters.
The printf.1 utility can be used portably to emulate any of the traditional behaviours of the echo utility as follows:
if [ "X$1" = "X-n" ]
then
shift
printf "%s" "$*"
else
printf "%s\n" "$*"
fi
New applications are encouraged to use printf instead of echo.
Below are the different flavors for echoing a string without a NEWLINE:
When representing an 8-bit character by using the escape convention \0n, the n must always be preceded by the digit zero (0).
For example, typing: echo 'WARNING:\07' will print the phrase WARNING: and sound the ``bell'' on your terminal. The use of single (or double) quotes (or two backslashes) is required to protect the ``\'' that precedes the ``07''.
Following the \0, up to three digits are used in constructing
the octal output character.
If, following the \0n, you
want to echo additional digits that are not part of the
octal representation, you must use the full 3-digit n.
For example, if you want to echo ``ESC 7''
you must use the three digits ``033'' rather than just the two digits ``33''
after the \0.
2 digits Incorrect: echo "\0337" | od -xc produces: df0a (hex) 337 (ascii)
3 digits Correct: echo "\00337" | od -xc produces: lb37 0a00 (hex) 033 7 (ascii)
For the octal equivalents of each character, see ascii.5
|
|
Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1997).
Last modified 21/April/97