LX0-104 · Question #4
How can the existing environment variable FOOBAR be suppressed for the execution of the script./myscript only?
The correct answer is C. env -u FOOBAR./myscript. To suppress an existing environment variable for a single command's execution without affecting the current shell's environment, the env -u command can be used. This command removes the specified variable from the environment passed to the executed command.
Question
Options
- Aunset -v FOOBAR;./myscript
- Bset -a FOOBAR="";./myscript
- Cenv -u FOOBAR./myscript
- Denv -i FOOBAR./myscript
How the community answered
(44 responses)- A7% (3)
- B2% (1)
- C77% (34)
- D14% (6)
Why each option
To suppress an existing environment variable for a single command's execution without affecting the current shell's environment, the `env -u` command can be used. This command removes the specified variable from the environment passed to the executed command.
The `unset -v FOOBAR` command unsets the variable in the current shell's environment, making the change persistent for the current shell session, which is not limited to the script's execution.
The `set -a` command marks variables for automatic export, and `FOOBAR=""` sets the variable to an empty string, but it does not suppress or remove it from the environment for the script's execution.
The `env -u FOOBAR` command removes the variable `FOOBAR` from the environment passed to the subsequent command `./myscript`, ensuring the script runs without that variable while the `FOOBAR` variable in the parent shell remains untouched.
The `env -i` command starts the command with an *empty* environment, meaning all existing variables are suppressed, which is more restrictive than just suppressing `FOOBAR`.
Concept tested: Environment variable manipulation (env command)
Source: https://www.man7.org/linux/man-pages/man1/env.1.html
Topics
Community Discussion
No community discussion yet for this question.