我如何解释配置文件的内容

Sla*_*098 3 bash .profile

检查~/.bash_profile节目内容:

codio@data-burma:~$ cat ~/.bash_profile
if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

cd /home/codio/workspace
codio@data-burma:~$
Run Code Online (Sandbox Code Playgroud)

所有这些代码.bash_profile是什么意思?

Yar*_*ron 5

下面的答案基于.bash_profile中对.bashrc中乔什斯泰格。有关详细信息,请查看该页面的内容。

根据 bash 手册页,.bash_profile为登录 shell.bashrc执行,而为交互式非登录 shell 执行。

大多数情况下,您不想为登录和非登录 shell 维护两个单独的配置文件——当您设置 a 时PATH,您希望它适用于两者。您可以通过.bashrc.bash_profile文件中获取资源来解决此问题,然后将 PATH 和通用设置放在 .bashrc 中。

为此,请将以下几行添加到.bash_profile

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
Run Code Online (Sandbox Code Playgroud)

上面的代码执行以下操作:

  1. 检查是否 ~/.bashrc存在。
  2. 如果文件存在它,source它(“执行它”)。