📅  最后修改于: 2023-12-03 15:13:02.142000             🧑  作者: Mango
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.
$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.
To view $PATH, type the following command in the Shell:
echo $PATH
This command will output a list of directories separated by colons (:).
To modify $PATH, there are two methods: temporary and permanent.
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.
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.
$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.