Run show-mode once with APP_MODE=debug without changing the current shell's APP_MODE.
Which form is appropriate?
env NAME=value command constructs an environment for that command only and does not change the parent shell's variable.
Detailed explanation
export APP_MODE=debug; show-modeIncorrect. export changes the current shell's exported value.
Incorrect. export changes the current shell's exported value.
env APP_MODE=debug show-modeCorrect. env APP_MODE=debug show-mode applies the value to one command.
Correct. env APP_MODE=debug show-mode applies the value to one command.
unset APP_MODE; show-mode debugIncorrect. This removes a value and passes a command argument instead.
Incorrect. This removes a value and passes a command argument instead.
echo APP_MODE=debug | show-modeIncorrect. A pipe sends text on stdin rather than setting an environment variable.
Incorrect. A pipe sends text on stdin rather than setting an environment variable.
Try it yourself
An example you can run in a temporary verification environment.
APP_MODE=normal; env APP_MODE=debug bash -c 'printf "child=%s\n" "$APP_MODE"'; printf 'parent=%s\n' "$APP_MODE"Expected result
child=debug
parent=normalKey points
- env builds a child environment
- The parent value is preserved
- The assignment precedes the command
Notes
- Environment: GNU coreutils env / Bash 5.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.