1ECHO(P) POSIX Programmer's Manual ECHO(P)
2
3
4
6 echo - write arguments to standard output
7
9 echo [string ...]
10
12 The echo utility writes its arguments to standard output, followed by a
13 <newline>. If there are no arguments, only the <newline> is written.
14
16 The echo utility shall not recognize the "--" argument in the manner
17 specified by Guideline 10 of the Base Definitions volume of
18 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines; "--"
19 shall be recognized as a string operand.
20
21 Implementations shall not support any options.
22
24 The following operands shall be supported:
25
26 string A string to be written to standard output. If the first operand
27 is -n, or if any of the operands contain a backslash ( '\' )
28 character, the results are implementation-defined.
29
30 On XSI-conformant systems, if the first operand is -n, it shall be
31 treated as a string, not an option. The following character sequences
32 shall be recognized on XSI-conformant systems within any of the argu‐
33 ments:
34
35 \a
36 Write an <alert>.
37
38 \b
39 Write a <backspace>.
40
41 \c
42 Suppress the <newline> that otherwise follows the final argument
43 in the output. All characters following the '\c' in the argu‐
44 ments shall be ignored.
45
46 \f
47 Write a <form-feed>.
48
49 \n
50 Write a <newline>.
51
52 \r
53 Write a <carriage-return>.
54
55 \t
56 Write a <tab>.
57
58 \v
59 Write a <vertical-tab>.
60
61 \\
62 Write a backslash character.
63
64 \0num
65 Write an 8-bit value that is the zero, one, two, or three-digit
66 octal number num.
67
68
69
71 Not used.
72
74 None.
75
77 The following environment variables shall affect the execution of echo:
78
79 LANG Provide a default value for the internationalization variables
80 that are unset or null. (See the Base Definitions volume of
81 IEEE Std 1003.1-2001, Section 8.2, Internationalization Vari‐
82 ables for the precedence of internationalization variables used
83 to determine the values of locale categories.)
84
85 LC_ALL If set to a non-empty string value, override the values of all
86 the other internationalization variables.
87
88 LC_CTYPE
89 Determine the locale for the interpretation of sequences of
90 bytes of text data as characters (for example, single-byte as
91 opposed to multi-byte characters in arguments).
92
93 LC_MESSAGES
94 Determine the locale that should be used to affect the format
95 and contents of diagnostic messages written to standard error.
96
97 NLSPATH
98 Determine the location of message catalogs for the processing of
99 LC_MESSAGES .
100
101
103 Default.
104
106 The echo utility arguments shall be separated by single <space>s and a
107 <newline> shall follow the last argument. Output transformations
108 shall occur based on the escape sequences in the input. See the OPER‐
109 ANDS section.
110
112 The standard error shall be used only for diagnostic messages.
113
115 None.
116
118 None.
119
121 The following exit values shall be returned:
122
123 0 Successful completion.
124
125 >0 An error occurred.
126
127
129 Default.
130
131 The following sections are informative.
132
134 It is not possible to use echo portably across all POSIX systems unless
135 both -n (as the first argument) and escape sequences are omitted.
136
137 The printf utility can be used portably to emulate any of the tradi‐
138 tional behaviors of the echo utility as follows (assuming that IFS has
139 its standard value or is unset):
140
141 * The historic System V echo and the requirements on XSI implementa‐
142 tions in this volume of IEEE Std 1003.1-2001 are equivalent to:
143
144
145 printf "%b\n" "$*"
146
147 * The BSD echo is equivalent to:
148
149
150 if [ "X$1" = "X-n" ]
151 then
152 shift
153 printf "%s" "$*"
154 else
155 printf "%s\n" "$*"
156 fi
157
158 New applications are encouraged to use printf instead of echo.
159
161 None.
162
164 The echo utility has not been made obsolescent because of its extremely
165 widespread use in historical applications. Conforming applications
166 that wish to do prompting without <newline>s or that could possibly be
167 expecting to echo a -n, should use the printf utility derived from the
168 Ninth Edition system.
169
170 As specified, echo writes its arguments in the simplest of ways. The
171 two different historical versions of echo vary in fatally incompatible
172 ways.
173
174 The BSD echo checks the first argument for the string -n which causes
175 it to suppress the <newline> that would otherwise follow the final
176 argument in the output.
177
178 The System V echo does not support any options, but allows escape
179 sequences within its operands, as described for XSI implementations in
180 the OPERANDS section.
181
182 The echo utility does not support Utility Syntax Guideline 10 because
183 historical applications depend on echo to echo all of its arguments,
184 except for the -n option in the BSD version.
185
187 None.
188
190 printf
191
193 Portions of this text are reprinted and reproduced in electronic form
194 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
195 -- Portable Operating System Interface (POSIX), The Open Group Base
196 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
197 Electrical and Electronics Engineers, Inc and The Open Group. In the
198 event of any discrepancy between this version and the original IEEE and
199 The Open Group Standard, the original IEEE and The Open Group Standard
200 is the referee document. The original Standard can be obtained online
201 at http://www.opengroup.org/unix/online.html .
202
203
204
205IEEE/The Open Group 2003 ECHO(P)