nerdexam
LPI

010-160 · Question #37

Which of the following commands adds the directory /new/dir/ to the PATH environment variable?

The correct answer is E. export PATH=/new/dir: $PATH. To prepend a directory to the PATH variable in bash, use the export command with correct variable assignment syntax and a colon separator between the new path and the existing PATH expansion.

The Power of the Command Line

Question

Which of the following commands adds the directory /new/dir/ to the PATH environment variable?

Options

  • A$PATH=/new/dir: $PATH
  • BPATH=/new/dir: PATH
  • Cexport PATH=/new/dir: $PATH
  • Dexport $PATH=/new/dir: $PATH
  • Eexport PATH=/new/dir: $PATH

How the community answered

(58 responses)
  • A
    2% (1)
  • B
    10% (6)
  • C
    2% (1)
  • D
    5% (3)
  • E
    81% (47)

Why each option

To prepend a directory to the PATH variable in bash, use the export command with correct variable assignment syntax and a colon separator between the new path and the existing PATH expansion.

A$PATH=/new/dir: $PATH

$PATH= attempts to assign to the shell's expanded value of PATH rather than the variable name itself, which is invalid bash syntax.

BPATH=/new/dir: PATH

Missing the export keyword means the updated PATH exists only in the current shell and is not inherited by child processes.

Cexport PATH=/new/dir: $PATH

A space between the colon and $PATH breaks the PATH string into two words during assignment, preventing correct path concatenation.

Dexport $PATH=/new/dir: $PATH

Using $PATH on the left side of the assignment (export $PATH=) attempts to assign to the expanded string rather than the variable name, which is invalid syntax.

Eexport PATH=/new/dir: $PATHCorrect

The export keyword makes the variable available to child processes. The assignment PATH=/new/dir:$PATH uses the bare variable name on the left side, places the new directory first, separates it from the current value with a colon, and expands the existing PATH using $PATH on the right - all required elements for correct PATH manipulation.

Concept tested: Modifying PATH environment variable in bash

Source: https://www.gnu.org/software/bash/manual/bash.html#index-export

Topics

#PATH variable#environment variables#export command#shell configuration

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice