nerdexam
CompTIA

LX0-104 · Question #273

To test a shell script called myscript, the environment variable FOOBAR must be removed temporarily. How can this be done?

The correct answer is C. env -u FOOBAR myscript. To temporarily remove an environment variable for a shell script, the env -u command can execute the script with the specified variable unset.

Shells, Scripting and Data Management

Question

To test a shell script called myscript, the environment variable FOOBAR must be removed temporarily. How can this be done?

Options

  • Aunset -v FOOBAR
  • Bset -a FOOBAR=""
  • Cenv -u FOOBAR myscript
  • Denv -i FOOBAR myscript

How the community answered

(22 responses)
  • A
    5% (1)
  • B
    14% (3)
  • C
    77% (17)
  • D
    5% (1)

Why each option

To temporarily remove an environment variable for a shell script, the `env -u` command can execute the script with the specified variable unset.

Aunset -v FOOBAR

`unset -v FOOBAR` would permanently remove the `FOOBAR` variable from the current shell's environment, which is not a temporary removal for only the script.

Bset -a FOOBAR=""

`set -a FOOBAR=""` would set the `FOOBAR` variable to an empty string and mark it for export, not remove or unset it.

Cenv -u FOOBAR myscriptCorrect

The `env -u FOOBAR myscript` command runs `myscript` with the `FOOBAR` environment variable unset specifically for the duration of that command. This allows testing the script in an isolated environment without affecting the calling shell's environment.

Denv -i FOOBAR myscript

`env -i FOOBAR myscript` would execute `myscript` in an *empty* environment, meaning all inherited variables are removed, which is too broad if only `FOOBAR` needs to be unset while others remain.

Concept tested: Environment variable manipulation using env

Source: https://man7.org/linux/man-pages/man1/env.1.html

Topics

#environment variables#shell scripting#env command

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice