LFCS · 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. The env command with the -u option can temporarily remove a specified environment variable for the duration of a single command's execution.
Question
Options
- Aunset -v FOOBAR;./myscript
- Bset -a FOOBAR="";./myscript
- Cenv -u FOOBAR./myscript
- Denv -i FOOBAR./myscript
How the community answered
(24 responses)- A4% (1)
- B4% (1)
- C83% (20)
- D8% (2)
Why each option
The `env` command with the `-u` option can temporarily remove a specified environment variable for the duration of a single command's execution.
`unset -v FOOBAR; ./myscript` would permanently unset `FOOBAR` in the current shell, not just for the `myscript` execution.
`set -a FOOBAR=""; ./myscript` would export `FOOBAR` with an empty string value to the script, not suppress or unset it from the environment.
The `env -u FOOBAR ./myscript` command executes `./myscript` with the `FOOBAR` environment variable specifically unset from its environment, without affecting the `FOOBAR` variable in the calling shell.
`env -i ./myscript` would start `./myscript` with an entirely empty environment (except for any variables explicitly specified with `env`), which is more drastic than just suppressing `FOOBAR`.
Concept tested: `env` command for environment modification
Source: https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html
Topics
Community Discussion
No community discussion yet for this question.