The current shell has several environment variables such as HOME.
Run printenv with an empty inherited environment and only LAB_MODE=test.
Which command is correct?
GNU env -i starts the command with an empty environment. Explicit NAME=VALUE assignments then add only the variables requested.
Detailed explanation
env LAB_MODE=test printenvIncorrect. Without -i, the current environment is inherited.
Incorrect. Without -i, the current environment is inherited.
unset HOME; printenvIncorrect. Removing HOME leaves all other environment variables inherited.
Incorrect. Removing HOME leaves all other environment variables inherited.
env -i LAB_MODE=test printenvCorrect. env -i clears the inherited environment and adds LAB_MODE only.
Correct. env -i clears the inherited environment and adds LAB_MODE only.
printenv -i LAB_MODE=testIncorrect. printenv lists variables; it does not provide env's -i execution mode.
Incorrect. printenv lists variables; it does not provide env's -i execution mode.
Try it yourself
An example you can run in a temporary verification environment.
env -i LAB_MODE=test printenvExpected result
LAB_MODE=testKey points
- env -i
- Environment inheritance
- NAME=VALUE command prefixes
Notes
- Environment: GNU coreutils 9.x
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.