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