Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

csh(1)

ksh(1)

sh(1)

echo(1)  —  Commands

NAME

echo - Writes its arguments to standard output

SYNOPSIS

Current Syntax (XPG4 conformant)

echo [string]

Obsolescent Syntax (not XPG4 conformant)

echo [-n] [string]

DESCRIPTION

The echo command writes the specified string to standard output. 

The echo command can operate in one of two modes: XPG4 conformant and not XPG4 conformant. The default mode is not XPG4 conformant. The echo command operates in XPG4 mode if the variable CMD_ENV is defined in your environment. In XPG4 mode, any -n operand is treated as a string rather than as an option.  The arguments are separated by spaces and a newline character follows the last string.  Use the echo command to produce diagnostic messages in command files and to send data into a pipe.  If there are no arguments, the echo command outputs a newline character. 

The echo command described here is the program /usr/bin/echo.  Both csh and sh shells ontain built-in echo subcommands, which do not necessarily work in the same way as the /usr/bin/echo command. 

The echo command recognizes the following special characters:

\aDisplays an alert character. 

\bDisplays a backspace character. 

\cSuppresses the newline character.  All characters following \c in the arguments are ignored. 

\fDisplays a formfeed character. 

\nDisplays a newline character. 

\rDisplays a carriage-return character. 

\tDisplays a tab character. 

\vDisplays a vertical tab character. 

\\Displays a backslash character. 

\numberDisplays an 8-bit character whose value is the 1-, 2- or 3-digit octal number, number.  The first digit of number must be a 0 (zero). 

FLAGS

-nNo newline is added to the output. 

EXAMPLES

     1.To write a message to standard output, enter:

echo Please insert diskette . . .

     2.To display a message containing special characters as listed in DESCRIPTION, enclose the message in quotes, as follows:

echo "\n\n\nI’m at lunch.\nI’ll be back at 1 p.m."

This skips three lines and displays the message:

I’m at lunch.
I’ll be back at 1 p.m.

Note

Note that you must enclose the message in quotation marks if it contains escape sequences such as \n.  Otherwise, the shell treats the backslash (\) as an escape character.  The previous command example, entered without the quotes, results in the following output:

nnnI’m at lunch.nI’ll be back at 1 p.m.

     3.To use echo with pattern-matching characters, enter:

echo The back-up files are: ∗.bak

This displays the message The back-up files are: and then displays the filenames in the current directory ending with .bak. 

     4.To add a single line of text to a file, enter:

echo Remember to set the shell search path to $PATH. >>notes

This adds the message to the end of the file notes after the shell substitutes the value of the PATH shell variable. 

     5.To write a message to the standard error output (sh only), enter:

echo Error: file already exists. >&2

Use this in shell procedures to write error messages.  If the >&2 is omitted, then the message is written to the standard output. 

Future Directions

Future releases will provide the XPG4 conformant behavior as the default behavior. The -n flag is being phased out of use. See the printf reference page for use in portable applications. 

RELATED INFORMATION

Commands: csh(1), ksh(1), sh(1). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026