📜  $path linux - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:13:02.142000             🧑  作者: Mango

Shell-Bash and the $PATH

Shell is a command-line interface that is used to interact with an operating system, such as Linux. Bash is one of the most popular Shell interpreters for Linux. One of the essential concepts when using the Shell is the $PATH.

What is $PATH?

$PATH is an environment variable that contains a list of directories separated by colons (:). When a user types a command in the Shell, the Shell looks for the executable file in each of these directories in the order specified in $PATH. Therefore, it is crucial to have the correct directories listed in $PATH so that the Shell can find the correct executable files.

Viewing $PATH

To view $PATH, type the following command in the Shell:

echo $PATH

This command will output a list of directories separated by colons (:).

Modifying $PATH

To modify $PATH, there are two methods: temporary and permanent.

Temporary modification

To temporarily modify $PATH, type the following command in the Shell:

export PATH=$PATH:/path/to/new/directory

This command will add a new directory to the end of $PATH. The new directory will only be available for the current Shell session.

Permanent modification

To permanently modify $PATH, it must be added to one of the startup files in the user's home directory. These files include .bash_profile, .bashrc, and .profile.

For example, to permanently add a new directory to $PATH, add the following line to .bashrc:

export PATH=$PATH:/path/to/new/directory

This command will add the new directory to $PATH every time the Shell is started.

Conclusion

$PATH is an essential concept for Shell users, and it is important to understand how it works and how to modify it. By knowing how to modify $PATH, users can ensure that the Shell can find the correct executable files, which can save time and frustration.