【问题标题】:/etc/profile does not appear to run/etc/profile 似乎没有运行
【发布时间】:2016-03-13 03:59:05
【问题描述】:

我在 OS X 上,根据 man bash /etc/profile 是 bash shell 的系统范围配置。

出于测试的目的,我打开了这个文件:

open_profile(){
    sudo chmod 777 /etc/profile
}

并添加了一个回显,以便我可以查看它是否真的在运行。

不是:

# System-wide .profile for sh(1)

echo "test_global"

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi

我在打开 bash shell 时看不到回声。

【问题讨论】:

  • chmod 777 -> nonononono!永远不要运行chmod 777。它几乎从来不需要!甚至不是为了“测试目的”。如果文件是可读的,那么它是可读的。如果它可以被需要写入它的usergroup 写入,那么它就是可写的。绝对零需要给每个人写权限,忘记chmod 让它回到正常状态正是跨国公司被黑客入侵的原因。只是不要这样做。曾经。我写了an introduction of Unix permissions。请阅读!
  • 你改变了你的默认外壳吗? echo $SHELL 报告什么?

标签: macos bash


【解决方案1】:

/etc/profile 仅对登录 shell 调用。要强制登录 shell 代替非登录 shell,请添加 --login。

bash --login

当 Bash 作为登录 shell 或作为带有 --login 选项的非登录 shell 调用时,它首先从文件 /etc/profile 中读取并执行命令(如果该文件存在)。读取该文件后,它会按顺序查找 ~/.bash_profile、~/.bash_login 和 ~/.profile,并从第一个存在且可读的文件中读取并执行命令。

【讨论】:

猜你喜欢
  • 2015-09-22
  • 2021-11-27
  • 1970-01-01
  • 2022-12-04
  • 1970-01-01
  • 1970-01-01
  • 2017-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多