1
0
mirror of https://github.com/skeeto/w64devkit.git synced 2026-10-24 17:39:18 +03:00
Files
w64devkit/man/man1/env.1
Christopher Wellons 880be39a58 Add manual pages for the BusyBox applets
A page for each applet in the kit, plus .so stubs for aliases such as
egrep and unxz. Each was written from the pinned busybox-w32 source with
the kit's patches and configuration, then checked against the source
and by experiment. The NOTES sections cover Windows behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 06:33:28 -04:00

384 lines
7.6 KiB
Groff

.TH ENV 1 2026-10-19 "w64devkit" "w64devkit Manual"
.SH NAME
env \- run a program in a modified environment, or print the environment
.SH SYNOPSIS
.B env
.RB [ \-i0 ]
.RB [ \-u
.IR name ]...\&
.RB [ \- ]
[\fIname\fB=\fIvalue\fR]...\&
.RI [ prog
.RI [ arg ...]]
.SH DESCRIPTION
.B env
changes the environment it inherited, then either runs
.I prog
in the changed environment or, when there is no
.IR prog ,
prints it.
It makes the changes in this order:
.IP 1. 4
With
.B \-i
or a lone
.BR \- ,
every inherited variable is removed.
.IP 2. 4
Each
.B \-u
.I name
is removed.
.IP 3. 4
Each
.IB name = value
operand sets a variable, from left to right.
So an assignment overrides a
.B \-u
of the same name.
.PP
After the options and any lone
.BR \- ,
an operand that contains an
.B =
is an assignment, and the first operand that does not is
.IR prog .
The operands after
.I prog
are its arguments and reach it unchanged, even if they contain an
.BR = .
.PP
With
.IR prog ,
.B env
runs it with its own standard input, standard output, and standard
error, waits for it, and exits with its exit status.
The lookup of
.I prog
uses the changed environment, so a
.B PATH
assignment takes effect, and with no
.B PATH
only applets and names that include a directory are found.
The lookup follows
.B Running commands
in
.BR busybox (1),
with one difference from the shell: a
.I prog
of
.IR /bin/name ,
.IR /usr/bin/name ,
.IR /sbin/name ,
or
.I /usr/sbin/name
runs the applet
.I name
if there is one, or else that file if it exists, or else the program
.I name
in
.BR PATH .
.PP
Without
.IR prog ,
.B env
writes the changed environment to standard output, one variable per
line as
.IB name = value\fR.
The variables it inherited come first, in the order Windows supplied
them.
New variables follow in the order they were added, starting with any
.B BB_GLOBBING
that busybox added; see
.BR ENVIRONMENT .
.SH OPTIONS
Options may be grouped, as in
.BR \-i0 .
They are recognized only before the first operand: everything from the
first operand on, even one that begins with a dash, is an operand.
.B \-\-
ends the options.
Long options may be shortened to any unambiguous prefix.
.TP
.BR \-i ", " \-\-ignore\-environment
Start with an empty environment.
.TP
.B \-
Same as
.BR \-i ,
but an operand, not an option.
It counts only as the first operand.
In any later position it is an ordinary operand.
.TP
.BR \-0 ", " \-\-null
Write each variable of the listing followed by a NUL octet instead of a
LF.
It has no effect when
.I prog
runs.
.TP
\fB\-u\fR \fIname\fR, \fB\-\-unset\fR \fIname\fR
Remove the variable
.I name
from the environment.
The option may be repeated.
Removing a variable that is not set is not an error.
The argument of the short option may be attached, as in
.BR \-uPATH ,
and the long option also takes it as
.BI \-\-unset= name\fR.
An argument that contains an
.B =
is not a name: it sets that variable, as an assignment would, and
removes nothing.
.TP
.B \-\-help
Print a usage message on standard output and exit with status 0.
It is recognized only as the first argument, and any further arguments
are ignored.
.SH ENVIRONMENT
Except for
.BR BB_GLOBBING ,
these are read from the changed environment, so the options and
assignments affect them.
.TP
.B BB_GLOBBING
Unless it is
.BR 0 ,
busybox expands wildcards in the arguments of
.B env
itself when it starts, as needed when run from
.BR cmd.exe .
If the variable is not set then, busybox sets it to
.BR 0 .
Because
.B env
passes its environment on, the listing then includes
.B BB_GLOBBING=0
and so does
.IR prog 's
environment, unless
.B \-i
or
.B \-u
removed it.
Without it, an applet run as
.I prog
expands wildcards in its arguments again, so
.B env \-i ls \(aq*.c\(aq
lists the matching files.
.TP
.B BB_OVERRIDE_APPLETS
Which names run an applet and which run a program from
.BR PATH ;
see
.BR busybox (1).
.TP
.BR BB_TERMINAL_MODE ", " BB_SKIP_ANSI_EMULATION
When standard output is a console, decide whether the console or busybox
interprets the escape sequences in the listing, such as for color.
See
.BR busybox (1).
.TP
.B CONEMUPID
When it is set and neither of the above is, busybox uses terminal mode
0: it turns virtual terminal output off and emulates escape sequences
itself.
.TP
.BR LC_ALL ", " LC_CTYPE ", " LANG
If the first of these that is set has the value
.BR C ,
the listing is written to a console without code page conversion, and
the console interprets the bytes in its own code page.
.TP
.B PATH
Where
.I prog
is looked up.
Directories are separated by semicolons.
.PP
Variables that affect every busybox applet are described in
.BR busybox (1).
.SH EXIT STATUS
.TP
.B 0
The environment was printed.
.TP
.B 1
An invalid option, or an option without its argument, with a usage
message on standard error.
Also an operand that cannot be set as a variable, such as one that
begins with
.BR = ,
with the message
.BR "env: putenv: Invalid argument" ,
or an error writing standard output.
.TP
.B 126
.I prog
was found but could not be started.
.TP
.B 127
.I prog
was not found.
.PP
For both of the last two, standard error gets
.PP
.RS 4
.EX
env: can\(aqt execute \(aq\fIprog\fR\(aq: \fIreason\fR
.EE
.RE
.PP
Otherwise the status is that of
.IR prog ;
see
.BR NOTES .
.SH EXAMPLES
Run
.B make
with a variable set for that run only:
.PP
.RS 4
.EX
$ env CFLAGS=\-O2 make
.EE
.RE
.PP
Run a command with a minimal environment:
.PP
.RS 4
.EX
$ env \-i PATH="$PATH" make
.EE
.RE
.PP
Run a command without a variable:
.PP
.RS 4
.EX
$ env \-u MAKEFLAGS make
.EE
.RE
.PP
Show the environment that the options and assignments build:
.PP
.RS 4
.EX
$ env \-i FOO=1 BAR=2
FOO=1
BAR=2
.EE
.RE
.PP
Count the variables, correctly even for values that contain newlines:
.PP
.RS 4
.EX
$ env \-0 | tr \-cd \(aq\e0\(aq | wc \-c
.EE
.RE
.SH NOTES
Windows has no exec.
.B env
starts
.I prog
as a child process, waits for it, and exits with its exit code.
A code above 255, such as an NTSTATUS value, is reduced to its low
byte, or to 255 when that is zero, after
.B env
writes a message giving the code in hex to standard error.
The codes that busybox treats as signals, such as an access violation
and Ctrl+C, are passed on unchanged.
.PP
While
.I prog
runs, Ctrl+C and Ctrl+Break do not end
.BR env .
A
.I prog
attached to the console receives them itself, and any other
.I prog
is ended, with its child processes, as if by
.BR SIGINT .
.PP
A
.I prog
that is not found is reported with status 127.
So is one that busybox does not consider executable: a directory, or a
file that has none of the suffixes
.BR .com ,
.BR .exe ,
.BR .sh ,
.BR .bat ,
and
.BR .cmd ,
does not begin with
.BR #!\& ,
and is not a PE image.
A file that busybox considers executable but that Windows cannot run,
such as an
.I .exe
that is not a valid program, gives status 126.
.PP
Variable names are case-insensitive.
An assignment to
.B Path
replaces
.BR PATH ,
and
.B \-u path
removes it.
The name takes the spelling of the assignment.
.PP
A variable may have an empty value, as in
.IB name =\fR,
which
.B env
keeps and passes on.
A name may not be empty: an operand that begins with
.B =
fails.
.PP
busybox runs this applet for a
.B #!/usr/bin/env
line in a script, so a line such as
.B #!/usr/bin/env sh
works; see
.BR busybox (1).
The rest of the line after the interpreter is a single argument, so
.B #!/usr/bin/env \-i sh
fails.
.PP
Differences from GNU
.BR env :
only
.BR \-i ,
.BR \-0 ,
.BR \-u ,
and their long forms exist, so there is no
.BR \-C ,
.BR \-S ,
or
.BR \-v ,
and there is no
.BR \-\-version .
An argument of
.B \-u
that contains an
.B =
sets a variable, and
.B \-0
with
.I prog
is accepted.
An invalid option gives status 1, not 125.
.PP
The listing ends each line with a bare LF, not CR LF.
.SH SEE ALSO
.BR busybox (1),
.BR printenv (1),
.BR sh (1),
.BR tr (1),
.BR wc (1)