Linux中的$ PATH是什么以及如何修改它 [英] What is this $PATH in Linux and how to modify it
问题描述
我对Linux中的$ PATH有一些疑问.
I have a few questions on this $PATH in Linux.
我知道它告诉shell搜索可执行文件的目录,所以:
I know it tells the shell which directories to search for executable files, so:
- 什么是环境变量?
- 如何更改其路径?并建议更改它?
- 如果我更改它,后果是什么?
推荐答案
要获取路径当前的$PATH
变量,请输入:
To get your path current $PATH
variable type in:
echo $PATH
它告诉您的Shell在哪里寻找二进制文件.
It tells your shell where to look for binaries.
是的,您可以对其进行更改-例如,使用自定义脚本将其添加到$PATH
文件夹中.
Yes, you can change it - for example add to the $PATH
folder with your custom scripts.
因此:如果您的脚本在/usr/local/myscripts
中执行,则必须输入脚本的完整路径:/usr/local/myscripts/myscript.sh
更改$PATH
变量后,您只需键入myscript.sh
即可执行脚本.
So: if your scripts are in /usr/local/myscripts
to execute them you will have to type in a full path to the script: /usr/local/myscripts/myscript.sh
After changing your $PATH
variable you can just type in myscript.sh
to execute script.
以下是RHEL中$PATH
的示例:
Here is an example of $PATH
from RHEL:
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/user/bin
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/user/bin
要更改$PATH
,您必须在/etc/profile
中为用户或全局$PATH
设置编辑~/.profile
(或~/.bash_profile
).
To change your $PATH
you have to either edit ~/.profile
(or ~/.bash_profile
) for user or global $PATH
setting in /etc/profile
.
$PATH
变量不正确的后果之一是,如果没有完整的$PATH
,shell将无法找到和执行程序.
One of the consequences of having inaccurate $PATH
variables is that shell will not be able to find and execute programs without a full $PATH
.
这篇关于Linux中的$ PATH是什么以及如何修改它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!