env Command
The env command displays environment variables or runs programs in a modified environment. It's useful for viewing current environment settings or executing commands with specific environment variables.
Syntax
Description
The env command can display all environment variables or run a command in a modified environment. It's commonly used in shell scripts and for debugging environment-related issues.
Key features:
- Display all environment variables
- Run commands with modified environment
- Clear environment before running commands
- Set temporary environment variables
- Useful for shell scripting and debugging
Common Options
| Option | Description |
|---|---|
-i |
Start with empty environment |
-u NAME |
Remove variable NAME from environment |
-0 |
End output lines with NUL character |
--help |
Display help information |
--version |
Show version information |
Examples
Display all environment variables
Shows all current environment variables and their values
Run command with environment variable
Runs ls with modified PATH variable
Set multiple environment variables
Runs command with multiple environment variables set
Start with clean environment
Starts bash with empty environment
Remove environment variable
Starts bash without the HOME variable
Display specific variable
Shows only PATH-related environment variables
Run script with custom environment
Runs script with debug and verbose flags set
Clean environment with minimal variables
Starts bash with only PATH and HOME set
Check if variable is set
Checks if DISPLAY variable is set
Temporary environment for testing
Runs date command with C locale