ECHO(1) | User Commands | ECHO(1) |
/usr/bin/echo [string]...
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 all have echo built-in commands, which, by default, is invoked if the user calls echo without a full pathname. See shell_builtins(1). sh's echo, ksh's echo, ksh93's echo, and /usr/bin/echo understand the back-slashed escape characters, except that sh's echo does not understand \a as the alert character. In addition, ksh's and ksh93's echo does not have an -n option. csh's echo and /usr/ucb/echo, on the other hand, have an -n option, but do not understand the back-slashed escape characters. sh and ksh determine whether /usr/ucb/echo is found first in the PATH and, if so, they adapt the behavior of the echo builtin to match /usr/ucb/echo.
string
\a
\b
\c
\f
\n
\r
\t
\v
\\
\0n
The printf(1) utility can be used portably to emulate any of the traditional behaviors of the echo utility as follows:
printf "%b\n" "$*"
if [ "X$1" = "X-n" ] then shift printf "%s" "$*" else printf "%s\n" "$*" fi
New applications are encouraged to use printf instead of echo.
You can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows:
example% /usr/bin/echo $PWD | tr '/' ' ' | wc -w
See tr(1) and wc(1) for their functionality.
Below are the different flavors for echoing a string without a NEWLINE:
Example 2 /usr/bin/echo
example% /usr/bin/echo "$USER's current directory is $PWD\c"
Example 3 sh/ksh shells
example$ echo "$USER's current directory is $PWD\c"
Example 4 csh shell
example% echo -n "$USER's current directory is $PWD"
Example 5 /usr/ucb/echo
example% /usr/ucb/echo -n "$USER's current directory is $PWD"
0
>0
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
CSI | Enabled |
Interface Stability | Committed |
Standard | See standards(7). |
For example, typing: echo 'WARNING:\07' prints the phrase WARNING: and sounds 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(7).
April 14, 2016 | OmniOS |