xref: /titanic_52/usr/src/man/man1/echo.1 (revision 7aa76ffc594f84c1c092911a84f85a79ddb44c73)
te
Copyright 1989 AT&T
Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved
Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
http://www.opengroup.org/bookstore/.
The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
This notice shall appear on any product containing this material.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
echo 1 "8 Apr 2008" "SunOS 5.11" "User Commands"
NAME
echo - echo arguments
SYNOPSIS

/usr/bin/echo [string]...
DESCRIPTION

The echo utility writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. If there are no arguments, only the NEWLINE character is written.

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 \ea as the alert character. In addition, ksh's and ksh93's echo does not have an -n option. sh's echo and /usr/bin/echo have an -n option if the SYSV3 environment variable is set (see ENVIRONMENT VARIABLES below). 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.

OPERANDS

The following operand is supported:

string

A string to be written to standard output. If any operand is "-n", it is treated as a string, not an option. The following character sequences is recognized within any of the arguments:

\ea

Alert character.

\eb

Backspace.

\ec

Print line without new-line. All characters following the \ec in the argument are ignored.

\ef

Form-feed.

\en

New-line.

\er

Carriage return.

\et

Tab.

\ev

Vertical tab.

\e\e

Backslash.

\e0n

Where n is the 8-bit character whose ASCII code is the 1-, 2- or 3-digit octal number representing that character.

USAGE

Portable applications should not use -n (as the first argument) or escape sequences.

The printf(1) utility can be used portably to emulate any of the traditional behaviors of the echo utility as follows:

The Solaris 2.6 operating environment or compatible version's /usr/bin/echo is equivalent to:

printf "%b\en" "$*"

The /usr/ucb/echo is equivalent to:

if [ "X$1" = "X-n" ]

then

 shift

 printf "%s" "$*"

else

 printf "%s\en" "$*"

fi

New applications are encouraged to use printf instead of echo.

EXAMPLES

Example 1 Finding how far below root your current directory is located

You can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows:

Echo your current-working-directory's full pathname.

Pipe the output through tr to translate the path's embedded slash-characters into space-characters.

Pipe that output through wc -w for a count of the names in your path.

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\ec"

Example 3 sh/ksh shells

example$ echo "$USER's current directory is $PWD\ec"

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"
ENVIRONMENT VARIABLES

See environ(5) for descriptions of the following environment variables that affect the execution of echo: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.

SYSV3

This environment variable is used to provide compatibility with INTERACTIVE UNIX System and SCO UNIX installation scripts. It is intended for compatibility only and should not be used in new scripts. This variable is applicable only for Solaris x86 platforms, not Solaris SPARC systems.

EXIT STATUS

The following error values are returned:

0

Successful completion.

>0

An error occurred.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPEATTRIBUTE VALUE
CSIEnabled
Interface StabilityCommitted
StandardSee standards(5).
SEE ALSO

ksh93(1), printf(1), shell_builtins(1), tr(1), wc(1), echo(1B), ascii(5), attributes(5), environ(5), standards(5)

NOTES

When representing an 8-bit character by using the escape convention \e0n, the n must always be preceded by the digit zero (0).

For example, typing: echo 'WARNING:\e\|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 "\|\e" that precedes the "07".

Following the \e0, up to three digits are used in constructing the octal output character. If, following the \e0n, 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 \e\|0.

2 digits Incorrect: echo "\e0337" | od -xc
 produces: df0a (hex)
 337 (ascii)
3 digits Correct: echo "\e00337" | od -xc
 produces: lb37 0a00 (hex)
 033 7 (ascii)

For the octal equivalents of each character, see ascii(5).