Correct option is B
In Linux, to add a new directory to the $PATH variable, the correct method is using the export command. This ensures that the new directory is appended to the existing $PATH and is available for the current shell session.
Example:
export PATH=$PATH:/new/directory
This command appends /new/directory to the existing $PATH. To make this change permanent, it can be added to the .bashrc or .bash_profile file.
Important Key Points:
1. $PATH is an
environment variable that defines the directories the shell searches for executable files.
2. The export command ensures the modified $PATH is available to the current session and child processes.
3. Changes made directly to $PATH are
temporary unless added to shell configuration files like .bashrc.
Knowledge Booster:
·
set PATH=/new/directory: Incorrect; set is not used for exporting environment variables.
·
add PATH:/new/directory: Incorrect; this syntax is invalid in Linux shells.
·
echo PATH:/new/directory: Incorrect; echo only displays the value but does not modify $PATH.
·
modify PATH=/new/directory:$PATH: Incorrect; modify is not a valid command in Linux.