Main index | Section 1 | 日本語 | Deutsch | Options |
The options are as follows:
| |
End each output line with NUL, not newline. | |
| |
Execute the utility with only those environment variables specified by name=value options. The environment inherited by env is ignored completely. | |
| |
Add the environment variable definitions from
login.conf(5)
for the specified user and login class to the environment, after
processing any
| |
| |
Search the set of directories as specified by altpath to locate the specified utility program, instead of using the value of the PATH environment variable. | |
| |
Split apart the given
string
into multiple strings, and process each of the resulting strings
as separate arguments to the
env
utility.
The
| |
| |
If the environment variable name is in the environment, then remove it before processing the remaining options. This is similar to the unset command in sh(1). The value for name must not include the ‘=’ character. | |
| |
Print verbose information for each step of processing done by the
env
utility.
Additional information will be printed if
| |
The above options are only recognized when they are specified before any name=value options.
If no
utility
is specified,
env
prints out the names and values of the variables in the environment.
Each name/value pair is separated by a new line unless
Spaces and tabs may be embedded in one of those new arguments by using single ("'") or double (‘amp;"’) quotes, or backslashes (‘\’). Single quotes will escape all non-single quote characters, up to the matching single quote. Double quotes will escape all non-double quote characters, up to the matching double quote. It is an error if the end of the string is reached before the matching quote character.
If
While processing the
string
value,
\c | Ignore the remaining characters in the string. This must not appear inside a double-quoted string. |
\f | Replace with a <form-feed> character. |
\n | Replace with a <new-line> character. |
\r | Replace with a <carriage return> character. |
\t | Replace with a <tab> character. |
\v | Replace with a <vertical tab> character. |
\# | Replace with a ‘#’ character. This would be useful when you need a ‘#’ as the first character in one of the arguments created by splitting apart the given string. |
\$ | Replace with a ‘$’ character. |
\_ | If this is found inside of a double-quoted string, then replace it with a single blank. If this is found outside of a quoted string, then treat this as the separator character between new arguments in the original string. |
\" | Replace with a <double quote> character. |
\ | Replace with a <single quote> character. |
\\ | Replace with a backslash character. |
The sequences for <single-quote> and backslash are the only sequences which are recognized inside of a single-quoted string. The other sequences have no special meaning inside a single-quoted string. All escape sequences are recognized inside of a double-quoted string. It is an error if a single ‘\’ character is followed by a character other than the ones listed above.
The processing of
Also,
Note that the way the kernel parses the ‘#!’ (first line) of an interpreted script has changed as of FreeBSD 6.0 . Prior to that, the FreeBSD kernel would split that first line into separate arguments based on any whitespace (space or <tab> characters) found in the line. So, if a script named /usr/local/bin/someport had a first line of:
#!/usr/local/bin/php -n -q -dsafe_mode=0
then the /usr/local/bin/php program would have been started with the arguments of:
arg[0] = '/usr/local/bin/php' arg[1] = '-n' arg[2] = '-q' arg[3] = '-dsafe_mode=0' arg[4] = '/usr/local/bin/someport'
plus any arguments the user specified when executing someport. However, this processing of multiple options on the ‘#!’ line is not the way any other operating system parses the first line of an interpreted script. So after a change which was made for FreeBSD 6.0 release, that script will result in /usr/local/bin/php being started with the arguments of:
arg[0] = '/usr/local/bin/php' arg[1] = '-n -q -dsafe_mode=0' arg[2] = '/usr/local/bin/someport'
plus any arguments the user specified. This caused a significant change in the behavior of a few scripts. In the case of above script, to have it behave the same way under FreeBSD 6.0 as it did under earlier releases, the first line should be changed to:
#!/usr/bin/env -S /usr/local/bin/php -n -q -dsafe_mode=0
The env utility will be started with the entire line as a single argument:
arg[1] = '-S /usr/local/bin/php -n -q -dsafe_mode=0'
and then
The kernel processing of an interpreted script does not allow a script to directly reference some other script as its own interpreter. As a way around this, the main difference between
#!/usr/local/bin/foo
and
#!/usr/bin/env /usr/local/bin/foo
is that the latter works even if /usr/local/bin/foo is itself an interpreted script.
Probably the most common use of env is to find the correct interpreter for a script, when the interpreter may be in different directories on different systems. The following example will find the ‘perl’ interpreter by searching through the directories specified by PATH.
#!/usr/bin/env perl
One limitation of that example is that it assumes the user's value
for
PATH
is set to a value which will find the interpreter you want
to execute.
The
#!/usr/bin/env -S -P/usr/local/bin:/usr/bin perl
The above finds
‘perl’
only if it is in
/usr/local/bin
or
/usr/bin.
That could be combined with the present value of
PATH,
to provide more flexibility.
Note that spaces are not required between the
#!/usr/bin/env -S-P/usr/local/bin:/usr/bin:${PATH} perl
The
env
utility does not take multibyte characters into account when
processing the
ENV (1) | April 24, 2020 |
Main index | Section 1 | 日本語 | Deutsch | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | Modern Unix impedes progress in computer science, wastes billions of dollars, and destroys the common sense of many who seriously use it. | ” |
— The Unix Haters' handbook |