Writes character strings to standard output.
echo [ String ... ]
The echo command writes character strings to standard output. Strings are separated by spaces, and a new-line character follows the last String parameter specified. If no String parameter is specified, a blank line (new-line character) is displayed.
Normally you could distinguish between a flag and a string that begins with a hyphen by using a -- (double hyphen). Since no flags are supported with the echo command, a -- (double hyphen) is treated literally.
The echo command recognizes the following escape conventions:
|\a||Displays an alert character.|
|\b||Displays a backspace character.|
|\c||Suppresses the new-line character that otherwise follows the final argument in the output. All characters following the \c sequence are ignored.|
|\f||Displays a form-feed character.|
|\n||Displays a new-line character.|
|\r||Displays a carriage return character.|
|\t||Displays a tab character.|
|\v||Displays a vertical tab character.|
|\\||Displays a backslash character.|
|\0Number||Displays an 8-bit character whose ASCII value is a 0-, 1-, 2-, or 3-digit octal number.|
Note: The bsh, ksh, and csh commands each contain a built-in echo subcommand. The echo command and the bsh and ksh echo subcommands work the same way. The csh echo subcommand does not work the same way as the echo command. For information on the echo subcommands, see "Bourne Shell Built-in Commands," "Regular Built-in Command Descriptons," and "C Shell Built-in Commands" in AIX Version 4.3 System User's Guide: Operating System and Devices.
The \ (backslash) is a quote character in the shell. This means that unless the \ is used with an escape character or enclosed in quotes, for example "\" or '\', the shell removes the backslashes when the command is expanded.
After shell expansion, the echo command writes the output based on the escape sequences in the input. Refer to the Backslash Reduction table for an example comparison of how backslashes in a command are first reduced by the shell and then by the echo command:
|Command Entered||After Shell Expansion||After echo Command Processing|
|echo hi\\\\there||echo hi\\there||hi\there|
|echo 'hi\\\\there'||echo 'hi\\\\there'||hi\\there|
|echo "hi\\\\there'||echo "hi\\there"||hi\there|
This command returns the following exit values:
|>0||An error occurred.|
echo Please insert diskette . . .
echo "\n\n\nI'm at lunch.\nI'll be back at 1:00."This skips three lines and displays the message:
I'm at lunch. I'll be back at 1:00.
Note: You must put the message in quotation marks if it contains escape sequences. Otherwise, the shell interprets the \ (backslash) as a metacharacter and treats the \ differently.
echo The back-up files are: *.bakThis usage displays the message The back-up files are: followed by the file names in the current directory ending with .bak.
echo Remember to set the shell search path to $PATH. >>notesThis usage adds the message to the end of the file notes after the shell substitutes the value of the PATH shell variable.
echo Error: file already exists. >&2This command redirects the error message to standard error. If the >&2 is omitted, the message is written to standard output.
|/usr/bin/echo||Contains the echo command.|
The bsh command, csh command, ksh command, printf command.
Input and Output Redirection Overview in AIX Version 4.3 System User's Guide: Operating System and Devices describes how the operating system processes input and output and how to use the redirect and pipe symbols.
The Shells Overview in AIX Version 4.3 System User's Guide: Operating System and Devices describes what shells are, the different types of shells, and how shells affect the way commands are interpreted.