The env command in Unix is used to display, set, or modify environment variables for a command or a shell session.
It can also run a command with a custom or empty set of environment variables, allowing you to control the environment for that command without affecting the rest of your session.
Run the command with a completely empty environment. It will ignore all existing environment variables.
Example:
-zsh
> env -i ls
This command will list the files and directories in the current directory, but it will run without any environment variables.
If ls or any command you use needs specific environment variables, for example custom PATH settings, it may fail or behave differently due to the lack of those variables.
-u
Remove the specified environment variable from the environment before running the command.
Example:
-zsh
> env -u PATH ls
Unsets the PATH environment variable before running the ls command, which list the content of the current directory.
-v
Provide more detailed information about the environment variables.
Example:
-zsh
> env -v LANG=fr_FR.UTF-8 ls
With -v, env will display the process of setting LANG before running ls.
This command line lists the contents of the current directory, potentially using French (fr_FR.UTF-8) if any message output is affected by LANG.
A possible Output could be:
# Output
# env: setting environment variable 'LANG' to 'fr_FR.UTF-8'
document.txt image.jpg