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.
env APP_MODE=debug show-modeCorrect. 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.
echo APP_MODE=debug | show-modeIncorrect. 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
- Use disposable shell sessions and harmless commands for experiments.
- Shell behavior can depend on Bash options and distribution defaults.
Foundation review
Place the operation
A command-specific environment is ideal for a one-run setting such as a debug or locale toggle.
Check the side effect
Print the value inside the child and again in the parent shell to confirm isolation.