Questão de Linux Administration #019e3987
How can the existing environment variable FOOBAR be suppressed for the execution of the script./myscript only?
unset -v FOOBAR;./myscript
set -a FOOBAR="";./myscript
env -u FOOBAR./myscript
env -i FOOBAR./myscript
Explicação Oficial / Explicações da Comunidade
Summary
This question tests the ability to temporarily suppress an environment variable for a single command without affecting the current shell. The correct approach uses env -u to unset a variable for the child process only.
How it Works
Environment variables are inherited by child processes. To suppress a variable for a specific command, you can modify the environment for that command only. The env utility runs a command with a modified environment. The -u option removes a variable from the environment before executing the command.
Why the correct answer is right
Option C (env -u FOOBAR ./myscript) correctly unsets the FOOBAR variable only for the execution of ./myscript. The original shell environment remains unchanged.
Why incorrect options are wrong
- A:
unset -v FOOBAR; ./myscriptunsetsFOOBARin the current shell, affecting subsequent commands. It does not limit the change to./myscriptonly. - B:
set -a FOOBAR=""; ./myscriptsetsFOOBARto an empty string in the current shell and marks it for export, but does not suppress it; it actually sets it to empty, which is different from unsetting. - D:
env -i FOOBAR ./myscriptstarts with an empty environment and then setsFOOBARto whatever follows (here it's interpreted as a command, causing an error). The-ioption clears all environment variables, which is too broad.