Linux Administration
medium

Questão de Linux Administration #019e3987

Enunciado da Questão
Linux Administration
#env
#unset
#environment-variable
#script-execution
Médio

How can the existing environment variable FOOBAR be suppressed for the execution of the script./myscript only?

A

unset -v FOOBAR;./myscript

B

set -a FOOBAR="";./myscript

C

env -u FOOBAR./myscript

Correta
D

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; ./myscript unsets FOOBAR in the current shell, affecting subsequent commands. It does not limit the change to ./myscript only.
  • B: set -a FOOBAR=""; ./myscript sets FOOBAR to 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 ./myscript starts with an empty environment and then sets FOOBAR to whatever follows (here it's interpreted as a command, causing an error). The -i option clears all environment variables, which is too broad.