1echo(1)                          User Commands                         echo(1)
2
3
4

NAME

6       echo - echo arguments
7

SYNOPSIS

9       /usr/bin/echo [string]...
10
11

DESCRIPTION

13       The  echo  utility writes its arguments, separated by BLANKs and termi‐
14       nated by a NEWLINE, to the standard output. If there are no  arguments,
15       only the NEWLINE character is written.
16
17
18       echo  is useful for producing diagnostics in command files, for sending
19       known data into a pipe, and for displaying the contents of  environment
20       variables.
21
22
23       The  C shell, the Korn shell, and the Bourne shell all have echo built-
24       in commands, which, by default, is invoked if the user calls echo with‐
25       out  a  full  pathname.  See  shell_builtins(1). sh's echo, ksh's echo,
26       ksh93's echo, and  /usr/bin/echo  understand  the  back-slashed  escape
27       characters,  except  that sh's echo does not understand \a as the alert
28       character. In addition, ksh's and ksh93's echo  does  not  have  an  -n
29       option.  sh's   echo  and  /usr/bin/echo have an -n option if the SYSV3
30       environment variable is set (see ENVIRONMENT  VARIABLES  below).  csh's
31       echo  and  /usr/ucb/echo,  on the other hand, have an -n option, but do
32       not understand the back-slashed escape characters. sh and ksh determine
33       whether /usr/ucb/echo is found first in the PATH and, if so, they adapt
34       the behavior of the echo builtin to match /usr/ucb/echo.
35

OPERANDS

37       The following operand is supported:
38
39       string    A string to be written to standard output. If any operand  is
40                 "-n", it is treated as a string, not an option. The following
41                 character sequences is recognized within  any  of  the  argu‐
42                 ments:
43
44                 \a      Alert character.
45
46
47                 \b      Backspace.
48
49
50                 \c      Print line without new-line. All characters following
51                         the \c in the argument are ignored.
52
53
54                 \f      Form-feed.
55
56
57                 \n      New-line.
58
59
60                 \r      Carriage return.
61
62
63                 \t      Tab.
64
65
66                 \v      Vertical tab.
67
68
69                 \\      Backslash.
70
71
72                 \0n     Where n is the 8-bit character whose  ASCII  code  is
73                         the  1-, 2- or 3-digit octal number representing that
74                         character.
75
76
77

USAGE

79       Portable applications should not use -n  (as  the  first  argument)  or
80       escape sequences.
81
82
83       The printf(1) utility can be used portably to emulate any of the tradi‐
84       tional behaviors of the echo utility as follows:
85
86           o      The Solaris 2.6 operating  environment  or  compatible  ver‐
87                  sion's /usr/bin/echo is equivalent to:
88
89                    printf "%b\n" "$*"
90
91
92
93           o      The /usr/ucb/echo is equivalent to:
94
95                    if [ "X$1" = "X-n" ]
96
97                    then
98
99                            shift
100
101                            printf "%s" "$*"
102
103                    else
104
105                            printf "%s\n" "$*"
106
107                    fi
108
109
110
111       New applications are encouraged to use printf instead of echo.
112

EXAMPLES

114       Example 1 Finding how far below root your current directory is located
115
116
117       You  can  use  echo to determine how many subdirectories below the root
118       directory (/) is your current directory, as follows:
119
120
121           o      Echo your current-working-directory's full pathname.
122
123           o      Pipe the output through tr to translate the path's  embedded
124                  slash-characters into space-characters.
125
126           o      Pipe  that  output through wc -w for a count of the names in
127                  your path.
128
129                    example% /usr/bin/echo $PWD | tr '/' ' ' | wc -w
130
131
132
133
134       See tr(1) and wc(1) for their functionality.
135
136
137
138       Below are the different flavors for echoing a string without a NEWLINE:
139
140       Example 2 /usr/bin/echo
141
142         example% /usr/bin/echo "$USER's current directory is $PWD\c"
143
144
145
146       Example 3 sh/ksh shells
147
148         example$ echo "$USER's current directory is $PWD\c"
149
150
151
152       Example 4 csh shell
153
154         example% echo -n "$USER's current directory is $PWD"
155
156
157
158       Example 5 /usr/ucb/echo
159
160         example% /usr/ucb/echo -n "$USER's current directory is $PWD"
161
162
163

ENVIRONMENT VARIABLES

165       See environ(5) for descriptions of the following environment  variables
166       that affect the execution of echo: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
167       and NLSPATH.
168
169       SYSV3    This environment variable is  used  to  provide  compatibility
170                with   INTERACTIVE  UNIX  System  and  SCO  UNIX  installation
171                scripts. It is intended for compatibility only and should  not
172                be  used  in new scripts. This variable is applicable only for
173                Solaris x86 platforms, not Solaris SPARC systems.
174
175

EXIT STATUS

177       The following error values are returned:
178
179       0     Successful completion.
180
181
182       >0    An error occurred.
183
184

ATTRIBUTES

186       See attributes(5) for descriptions of the following attributes:
187
188
189
190
191       ┌─────────────────────────────┬─────────────────────────────┐
192       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
193       ├─────────────────────────────┼─────────────────────────────┤
194       │Availability                 │SUNWcsu                      │
195       ├─────────────────────────────┼─────────────────────────────┤
196       │CSI                          │Enabled                      │
197       ├─────────────────────────────┼─────────────────────────────┤
198       │Interface Stability          │Committed                    │
199       ├─────────────────────────────┼─────────────────────────────┤
200       │Standard                     │See standards(5).            │
201       └─────────────────────────────┴─────────────────────────────┘
202

SEE ALSO

204       ksh93(1),  printf(1),  shell_builtins(1),   tr(1),   wc(1),   echo(1B),
205       ascii(5), attributes(5), environ(5), standards(5)
206

NOTES

208       When  representing  an  8-bit  character by using the escape convention
209       \0n, the n must always be preceded by the digit zero (0).
210
211
212       For example, typing: echo 'WARNING:\07' prints the phrase WARNING:  and
213       sounds  the  "bell"  on  your  terminal.  The use of single (or double)
214       quotes (or two backslashes) is required to protect the  "\"  that  pre‐
215       cedes the "07".
216
217
218       Following the \0, up to three digits are used in constructing the octal
219       output character. If, following the \0n, you want  to  echo  additional
220       digits  that are not part of the octal representation, you must use the
221       full 3-digit n. For example, if you want to echo "ESC 7" you  must  use
222       the  three  digits "033" rather than just the two digits "33" after the
223       \0.
224
225         2 digits         Incorrect:      echo "\0337" | od -xc
226                          produces:       df0a                     (hex)
227                                          337                      (ascii)
228         3 digits         Correct:        echo "\00337" | od -xc
229                          produces:       lb37 0a00                (hex)
230                                          033 7                    (ascii)
231
232
233
234
235       For the octal equivalents of each character, see ascii(5).
236
237
238
239SunOS 5.11                        8 Apr 2008                           echo(1)
Impressum