/bin/bash 复制代码

/bin/bash 复制代码

如何编辑我的.profile文件来为我的变量设置永久值PATH

还有其他文件需要编辑吗?(这是在 CentOs 6.2 上)

答案1

您可能希望在 shell 的 rcfile(.bashrc、.zshrc 等)中执行此操作。您需要添加类似以下内容:

export PATH=$PATH:/new/folder/path

如果您只想附加文件路径。或者您可以巧妙地使用它并创建一个路径文件(对于 zsh,我有一个 .zpath 文件)。在那里您可以执行以下操作:

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
export PATH

现在,每次获取该文件时(source ~/.zpath例如),它都会将这些路径加载到您的环境中。您可以将其添加source ~/.zpath到 rcfile 中,这样每次登录或创建新 shell 时都会发生这种情况。

答案2

 - Go to /etc/profile 
Go to line # Path manipulation if [ "$EUID" = "0]; then
       pathmunge /sbin
       pathmunge /usr/sbin
       pathmunge /usr/local/sbin

   ***add your path like this- pathmunge /your/path

** 或者你改变用户 ID(0 是 root)或者添加更多条件,例如

   if [ "$EUID" >= "0" ]; then
       pathmunge /sbin
       pathmunge /usr/sbin
       pathmunge /usr/local/sbin 
   ** to find your id type this command at prompt #id

并重启系统

答案3

我认为为此制作一个 bashscript 您需要使用 profile.d /etc/profile 可以通过更新替换吗?

vi /etc/profile.d/path.sh

/bin/bash 复制代码

导出 PATH=$PATH:/new/folder/path:/opt/anotherpath:/etc/etc/etc

保存并 chmod +x /etc/profile.d/path.sh

相关内容