1 .\" Copyright (c) 1980, 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 4. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" From @(#)printenv.1 8.1 (Berkeley) 6/6/93
31 .\" From FreeBSD: src/usr.bin/printenv/printenv.1,v 1.17 2002/11/26 17:33:35 ru Exp
39 .Nd set environment and execute command, or print environment
46 .Op Ar name Ns = Ns Ar value ...
47 .Op Ar utility Op Ar argument ...
51 utility executes another
53 after modifying the environment as
54 specified on the command line.
56 .Ar name Ns = Ns Ar value
57 option specifies the setting of an environment variable,
61 All such environment variables are set before the
65 The options are as follows:
66 .Bl -tag -width indent
70 with only those environment variables specified by
71 .Ar name Ns = Ns Ar value
73 The environment inherited
76 is ignored completely.
79 Search the set of directories as specified by
81 to locate the specified
83 program, instead of using the value of the
90 into multiple strings, and process each of the resulting strings
91 as separate arguments to the
96 option recognizes some special character escape sequences and
97 also supports environment-variable substitution, as described
101 If the environment variable
103 is in the environment, then remove it before processing the
105 This is similar to the
116 Print verbose information for each step of processing done by the
119 Additional information will be printed if
121 is specified multiple times.
124 The above options are only recognized when they are specified
126 .Ar name Ns = Ns Ar value
133 prints out the names and values
134 of the variables in the environment, with one name/value pair per line.
136 .Ss Details of Fl S Ss (split-string) processing
137 The processing of the
139 option will split the given
141 into separate arguments based on any space or <tab> characters found in the
143 Each of those new arguments will then be treated as if it had been
144 specified as a separate argument on the original
148 Spaces and tabs may be embedded in one of those new arguments by using
153 quotes, or backslashes
155 Single quotes will escape all non-single quote characters, up to
156 the matching single quote.
157 Double quotes will escape all non-double quote characters, up to
158 the matching double quote.
159 It is an error if the end of the
161 is reached before the matching quote character.
165 would create a new argument that starts with the
167 character, then that argument and the remainder of the
172 sequence can be used when you want a new argument to start
175 character, without causing the remainder of the
183 processing will treat certain character combinations as escape
184 sequences which represent some action to take.
185 The character escape sequences are in backslash notation.
186 The characters and their meanings are as follows:
188 .Bl -tag -width indent -offset indent -compact
190 Ignore the remaining characters in the
192 This must not appear inside a double-quoted string.
194 Replace with a <form-feed> character.
196 Replace with a <new-line> character.
198 Replace with a <carriage return> character.
200 Replace with a <tab> character.
202 Replace with a <vertical tab> character.
207 This would be useful when you need a
209 as the first character in one of the arguments created
210 by splitting apart the given
217 If this is found inside of a double-quoted string, then replace it
219 If this is found outside of a quoted string, then treat this as the
220 separator character between new arguments in the original
223 Replace with a <double quote> character.
225 Replace with a <single quote> character.
227 Replace with a backslash character.
230 The sequences for <single-quote> and backslash are the only sequences
231 which are recognized inside of a single-quoted string.
232 The other sequences have no special meaning inside a single-quoted
234 All escape sequences are recognized inside of a double-quoted string.
235 It is an error if a single
237 character is followed by a character other than the ones listed above.
241 also supports substitution of values from environment variables.
242 To do this, the name of the environment variable must be inside of
246 The common shell syntax of
249 All values substituted will be the values of the environment variables
250 as they were when the
252 utility was originally invoked.
253 Those values will not be checked for any of the escape sequences as
256 .Ar name Ns = Ns Ar value
257 will not effect the values used for substitution in
263 processing can not reference the value of the special parameters
264 which are defined by most shells.
267 can not recognize special parameters such as:
274 if they appear inside the given
277 .Ss Use in shell-scripts
280 utility is often used as the
282 on the first line of interpreted scripts, as
286 Note that the way the kernel parses the
288 (first line) of an interpreted script has changed as of
292 kernel would split that first line into separate arguments based
293 on any whitespace (space or <tab> characters) found in the line.
294 So, if a script named
295 .Pa /usr/local/bin/someport
298 .Dl "#!/usr/local/bin/php -n -q -dsafe_mode=0"
301 .Pa /usr/local/bin/php
302 program would have been started with the arguments of:
303 .Bd -literal -offset indent
304 arg[0] = '/usr/local/bin/php'
307 arg[3] = '-dsafe_mode=0'
308 arg[4] = '/usr/local/bin/someport'
311 plus any arguments the user specified when executing
313 However, this processing of multiple options on the
315 line is not the way any other operating system parses the
316 first line of an interpreted script.
317 So after a change which was made for
319 release, that script will result in
320 .Pa /usr/local/bin/php
321 being started with the arguments of:
322 .Bd -literal -offset indent
323 arg[0] = '/usr/local/bin/php'
324 arg[1] = '-n -q -dsafe_mode=0'
325 arg[2] = '/usr/local/bin/someport'
328 plus any arguments the user specified.
329 This caused a significant change in the behavior of a few scripts.
330 In the case of above script, to have it behave the same way under
332 as it did under earlier releases, the first line should be
335 .Dl "#!/usr/bin/env -S /usr/local/bin/php -n -q -dsafe_mode=0"
339 utility will be started with the entire line as a single
342 .Dl "arg[1] = '-S /usr/local/bin/php -n -q -dsafe_mode=0'"
346 processing will split that line into separate arguments before
348 .Pa /usr/local/bin/php .
355 environment variable to locate the requested
357 if the name contains no
359 characters, unless the
361 option has been specified.
364 An exit status of 126 indicates that
366 was found, but could not be executed.
367 An exit status of 127 indicates that
373 utility is often used as part of the first line of an interpreted script,
374 the following examples show a number of ways that the
376 utility can be useful in scripts.
378 The kernel processing of an interpreted script does not allow a script
379 to directly reference some other script as its own interpreter.
380 As a way around this, the main difference between
382 .Dl #!/usr/local/bin/foo
384 .Dl "#!/usr/bin/env /usr/local/bin/foo"
386 is that the latter works even if
387 .Pa /usr/local/bin/foo
388 is itself an interpreted script.
390 Probably the most common use of
392 is to find the correct interpreter for a script, when the interpreter
393 may be in different directories on different systems.
394 The following example will find the
396 interpreter by searching through the directories specified by
399 .Dl "#!/usr/bin/env perl"
401 One limitation of that example is that it assumes the user's value
404 is set to a value which will find the interpreter you want
408 option can be used to make sure a specific list of directories is
409 used in the search for
413 option is also required for this example to work correctly.
415 .Dl "#!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl"
423 That could be combined with the present value of
425 to provide more flexibility.
426 Note that spaces are not required between the
432 .Dl "#!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl"
438 option as a synonym for
454 options are non-standard extensions supported by
456 but which may not be available on other operating systems.
466 options were added in
471 utility does not handle values of
473 which have an equals sign
475 in their name, for obvious reasons.
479 utility does not take multibyte characters into account when
482 option, which may lead to incorrect results in some locales.