9.3.9 echo command (outputs what is specified in arguments to the standard output)
Syntax
echo [-n] [-e|-E] [args ...]
Description
This command outputs what is specified in arguments to the standard output.
During the output processing, escape characters that begin with a backslash (\) are replaced. The following table shows the escape characters that are replaced:
Escape character |
Meaning |
---|---|
\a |
Alert character (bell) |
\b |
Backspace character |
\c |
Suppress trailing linefeed (characters after \c are not output) |
\f |
Formfeed character (page break) |
\n |
Linefeed character |
\r |
Carriage return character |
\t |
Tab character |
\v |
Vertical tab character |
\0nnn#1 |
ASCII character represented by one, two, or three octal digits (0 to 7) |
\xnn#2 |
ASCII character represented by one or two hexadecimal digits (0 to 9, a to f, A to F) |
\\ |
A single backslash character |
- #1
If a specified ASCII character consists of one or two digits and two or one leading zeros, respectively, are added to make it three digits, the ASCII character will still be treated as consisting of only one or two digits. For example, the following three specifications are all interpreted as being the same, in which case the alert character (bell) is output three times:
echo -e "\07"
echo -e "\007"
echo -e "\0007"
- #2
Enabled only when YES is specified in the ESCAPE_SEQ_ECHO_HEX environment setting parameter. For details about the ESCAPE_SEQ_ECHO_HEX parameter, see 7.3.16 ESCAPE_SEQ_ECHO_HEX parameter (specifies whether ASCII code characters in hexadecimal notation are to be interpreted as escape characters) in 7. Parameters Specified in the Environment Files.
If a specified ASCII character consists of one digit and a leading zero is added to make it two digits, the ASCII character will still be treated as consisting of only one digit. For example, the following two specifications are interpreted as being the same, in which case the linefeed character is output twice:
echo -e "\xA"
echo -e "\x0A"
If you want to replace an escape character, enclose the -e option argument in single or double quotation marks (' or "), as in Example 2 below. The following examples show how escape characters are interpreted depending on whether quotation marks are used and whether the -e or -E option is specified.
In this example, ta is output to the standard output:
echo -e \ta
In this example, tab-charactera is output to the standard output:
echo -e "\ta"
In this example, ta is output to the standard output:
echo -E \ta
In this example, \ta is output to the standard output:
echo -E "\ta"
- Options specified for commands and interpretation of arguments
If the characters specified as the arguments to the echo command are all valid option characters, they are interpreted as options. For example, because the letters in eEn are all valid option characters, they are interpreted as options in the following example:
echo -eEn
However, if even one character is not a valid option character, the characters are interpreted as an args value. In the next example, because a is not a valid option character, -eEna is interpreted as an args value, which will be sent to the standard output.
echo -eEna
Finally, when an argument is enclosed in quotation marks, the entire enclosed character string is interpreted as a single argument. In the next example, because the space is not a valid option character, -e a is interpreted as an args value, which will be sent to the standard output.
echo "-e a"
- Interpretation of escape characters (-e and -E options)
Escape characters are interpreted as follows, depending on the specification of the -e and -E options:
When the -e option is specified, escape characters are interpreted.
When the -E option is specified, escape characters are not interpreted.
When the -e and -E options are both specified, the option specified last takes effect.
When neither the -e nor the -E option is specified, the processing depends on the specification of the ESCAPE_SEQ_ECHO_DEFAULT environment setting parameter. For details about the ESCAPE_SEQ_ECHO_DEFAULT parameter, see 7.3.15 ESCAPE_SEQ_ECHO_DEFAULT parameter (defines the action of the echo command when the escape-character option is omitted) in 7. Parameters Specified in the Environment Files.
Arguments
- -n
Specifies that trailing linefeeds are to be omitted from the output to the standard output.
- -e
Specifies that escape characters are to be interpreted. The escape characters to be interpreted are determined by the specification of the ESCAPE_SEQ_ECHO_HEX environment setting parameter. If you want escape characters to be interpreted, enclose them in single or double quotation marks (' or ").
- -E
Specifies that escape characters are not to be interpreted.
- args
Specifies the arguments (what it is that is to be output).
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Error termination |
Notes
Even if the command syntax of this regular built-in command is invalid, it does not exit the shell that is executing the command.
If an escape character is specified using an ASCII code in hexadecimal notation, the result is the same as when the escape character is specified directly.
In both of the following specifications, atab-characterb is output:
echo -e "a\tb" echo -e "a\x09b"
In both of the following specifications, alinefeed-characterb is output to out.txt, but the linefeed character will be CR+LF (Windows only):
echo -e "a\nb" > out.txt echo -e "a\x0ab" > out.txt
If a value outside the ASCII code range is specified when escape characters are expressed as ASCII character strings, the content to be output follows the character encoding specified for the terminal and unprintable characters might produce an incorrect output.
If you specify a path name for an argument, execute the echo command in an environment in which the -E option is specified or NO is specified in the ESCAPE_SEQ_ECHO_DEFAULT parameter in order to prevent the backslash (\) from being replaced as an escape character.
For example, the path name (d:\a\b\c) is not output correctly by any of the following commands:
FILE="d:\\a\\b\\c" echo $FILE echo "$FILE" echo "d:\\a\\b\\c" echo 'd:\a\b\c'
The path name (d:\a\b\c) is output correctly by all the following commands:
FILE="d:\\a\\b\\c" echo -E $FILE echo -E "$FILE" echo -E "d:\\a\\b\\c" echo -E 'd:\a\b\c' FILE="d:\\\\a\\\\b\\\\c" echo $FILE echo 'd:\\a\\b\\c' echo d:\\\\a\\\\b\\\\c
Example
Output the variable LANG.
Contents of the job definition script
echo $LANG
Contents of the STDOUT file of the execution job
******** JOB SCOPE STDOUT ******** ja_JP.eucJP