nerdexam
CompTIA

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.

Shells, Scripting and Data Management

Question

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

Options

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

How the community answered

(44 responses)
  • A
    7% (3)
  • B
    2% (1)
  • C
    77% (34)
  • D
    14% (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.

Aunset -v FOOBAR;./myscript

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.

Bset -a FOOBAR="";./myscript

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.

Cenv -u FOOBAR./myscriptCorrect

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.

Denv -i FOOBAR./myscript

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

#environment variables#env command#script execution

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice