env - run a program in a modified environment
| Use Case | Command | Description |
|---|---|---|
| π§Ή Run with empty environment | env -i command | Start with no environment variables |
| π§ Set custom environment variables | env NAME=VALUE command | Run command with modified environment |
| β Remove a variable | env -u NAME command | Unset a specific environment variable |
| π Change working directory | env -C DIR command | Run command in different directory |
| π Split string for shebang | #!/usr/bin/env -S perl -w -T | Pass multiple arguments in script shebang |
| π¦ Handle signals | env --default-signal=PIPE seq inf | head -n1 | Reset signal handler to default |
| π Print environment | env | Display current environment (no command) |
env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
Set each NAME to VALUE in the environment and run COMMAND.
Mandatory arguments to long options are mandatory for short options too.
π§Ή -i, --ignore-environment
Start with an empty environment
π -0, --null
End each output line with NUL, not newline
β -u, --unset=NAME
Remove variable from the environment
π -C, --chdir=DIR
Change working directory to DIR
βοΈ -S, --split-string=S
Process and split S into separate arguments; used to pass multiple arguments on sheβbang lines
π« --block-signal[=SIG]
Block delivery of SIG signal(s) to COMMAND
π --default-signal[=SIG]
Reset handling of SIG signal(s) to the default
π€« --ignore-signal[=SIG]
Set handling of SIG signals(s) to do nothing
π --list-signal-handling
List nonβdefault signal handling to stderr
π -v, --debug
Print verbose information for each processing step
β --help
Display this help and exit
π --version
Output version information and exit
π A mere - implies -i. If no COMMAND, print the resulting environment.
β οΈ SIG may be a signal name like PIPE, or a signal number like 13. Without SIG, all known signals are included. Multiple signals can be commaβseparated.
The -S option allows specifying multiple parameters in a script. Running a script named 1.pl containing the following first line:
#!/usr/bin/env -S perl -w -T
...
Will execute perl -w -T 1.pl.
Without the -S parameter the script will likely fail with:
/usr/bin/env: 'perl -w -T': No such file or directory
See the full documentation for more details.
This option allows setting a signal handler to its default action, which is not possible using the traditional shell trap command. The following example ensures that seq will be terminated by SIGPIPE no matter how this signal is being handled in the process invoking the command.
sh -c 'env --default-signal=PIPE seq inf | head -n1'
POSIX's exec(2) pages says:
βmany existing applications wrongly assume that they start with certain signals set to the default action and/or unblockedβ¦. Therefore, it is best not to block or ignore signals across execs without explicit reason to do so, and especially not to block signals across execs of arbitrary (not closely cooperating) programs.β
Written by Richard Mlynarik, David MacKenzie, and Assaf Gordon.
GNU coreutils online help: https://www.gnu.org/software/coreutils/
Report any translation bugs to https://translationproject.org/team/
Copyright Β© 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later https://gnu.org/licenses/gpl.html.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
sigaction(2), sigprocmask(2), signal(7)
Full documentation: https://www.gnu.org/software/coreutils/env
or available locally via: info '(coreutils) env invocation'
Generated by phpman v4.10.0-7-g98e9fd5 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-09-03 19:02 @216.73.216.23
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)