加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – $HOME / bin目录不在$PATH上

发布时间:2020-12-16 01:44:30 所属栏目:安全 来源:网络整理
导读:在我的?/ .profile中我有一个最后一个块应该加载我的个人bin /目录,如下所示: # set PATH so it includes user's private bin if it existsif [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH"fi 但它似乎没有加载: echo $PATH/usr/local/bin:/usr/bin:/
在我的?/ .profile中我有一个最后一个块应该加载我的个人bin /目录,如下所示:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

但它似乎没有加载:

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

为什么这不起作用?

我的shell是bash.

编辑跳跳虎

echo $0 => bash

echo $HOME => /home/student

whoami => student

less /etc/*-release => 
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

解决方法

从?/ .profile的顶部:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1),if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

所以(如果你使用bash作为你的shell)我猜你的系统上有?/ .bash_profile或?/ .bash_login.选择一个并编辑它以包括:

export PATH=$PATH:$HOME/bin

然后保存并输出?/ .bash_login或注销并重新登录.

编辑:

你说$HOME都缺少?/ .bash_profile和?/ .bash_login.我想我们需要确认一些事情.请在原始问题中发布以下结果:

echo $0
echo $HOME
whoami
less /etc/*-release

编辑2:

就个人而言,我不知道为什么?/ .profile不会根据提供的信息和文档包含在您的案例中.在测试的时候,我确实注意到当我进入ssh时我的?/ .profile被扫描但是当我启动一个新的终端时.

但是,有一个简单的解决方案允许$HOME / bin包含在您的交互式shell中.编辑(创建,如果不存在)?/ .bashrc并添加以下行:

export PATH=$PATH:$HOME/bin

保存,注销并重新登录,或者来源?/ .bashrc.

如果您愿意,可以扩展导出行以检查$HOME / bin是否存在:

if [ -d "$HOME/bin" ]
then
    export PATH=$PATH:$HOME/bin
fi

为什么?/ .bashrc而不是另一个文件?个人偏好,似乎也更可靠.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读