I will describe the terminal command PATH
.
A command to add a command search path
.
The command search path
is a path that searches for the command executable file.
$ ls
/bin/ls
For example, suppose you run $ ls
, which references folders and files as above, and you have an executable file with the same name, ls
, under the / bin
directory.
Since $ ls
is executing the command without specifying the path, the shell will find the executable file corresponding to the command from each directory.
This path to find is called the command search path
, and you can add this path with the PATH
command.
You can check it with $ echo $ PATH
. In a certain environment, it will be displayed as follows.
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
The paths are separated by :
The six / usr / local / bin
, / usr / bin
, / bin
, / usr / sbin
, / sbin
, and/ usr / local / sbin
are the search command path
. It is set.
You can check it with $ which ls
. The execution result is as follows.
$ which ls
#Execution result
/bin/ls
In this case, it has priority and is executed from the one on the left output by $ echo $ PATH
.
For example, in the following cases
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
It is executed from / usr / local / bin
.
The priority is / usr / local / bin
> / usr / bin
> / bin
> / usr / sbin
> / sbin
>/ usr / local / sbin
.
To add PATH, write it in the .bashrc
or .bash_profile
file in the ʻexport PATH = $ PATH: command search path` format you want to add.
.bashrc
export PATH=$PATH:Command search path you want to add
.bash_profile
export PATH=$PATH:Command search path you want to add
The file that describes the PATH can be either .bashrc
or .bash_profile
.
$ source ~/.bashrc
$ source ~/.bash_profile
If you do not execute each described file with the source command, the path will not pass.
Display and set environment variables.
export -p
#Output result(Only a part is described)
declare -x PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
declare -x LANG="ja_JP.UTF-8"
declare -x SHELL="/bin/bash"
The set environment variables are displayed.
For example, to set the environment variable $ ULB
, set as follows.
$ export ULB=/usr/local/bin
$ echo $ULB
/usr/local/bin #Output result
I have confirmed that it is set with $ echo $ ULB
.
ls /usr/local/bin
ls $ULB
Both commands produce similar results.
$ echo $ULB
/usr/local/bin #Output result
$ export ULB=/u/l/b
$ echo $ULB
/u/l/b #Output result
You can also overwrite environment variables as described above.
It can be deleted with the ʻunset` command.
$ unset ULB #[$]Does not have to be entered.
$ echo $ULB
#Nothing is output.
$ export PATH=Command search path you want to add:$PATH
The command search path has the highest priority from the left, so describe it like this.
Introduction to Linux ~ What is "passing through" ~ https://qiita.com/Naggi-Goishi/items/2c49ea50602ea80bf015
Recommended Posts