解释〜/ .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. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi # set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi
任何人都可以解释~/.profile
文件的内容吗? 所以当你进入~/.profile
文件时,所有的写作意味着什么?
简化版:
if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi
这部分检查了什么~/.profile
本身是由Bash实例提供的,如果是这种情况来源依次~/.bashrc
; 这是一种包含存储在~/.bashrc
的用户设置的方法,例如也包含在登录shell中,通常不会提供~/.bashrc
;
if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi
这部分检查是否存在~/bin
,如果是这种情况,则将~/bin
到$PATH
的当前值; 这样做是为了使~/bin
存在的潜在可执行文件/脚本优先于$PATH
包含的其他路径中存在的可执行文件/脚本(例如,通过在~/bin
放置一个名为cat
的可执行文件,当运行cat
,可执行文件将在其中运行)通常的地方/bin/cat
)。
详细版本:
if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi
这部分检查$BASH_VERSION
的扩展是否具有非零长度( if [ -n "$BASH_VERSION" ]
),如果是这种情况,如果$HOME/.bashrc
的扩展存在并且是常规文件( if [ -f "$HOME/.bashrc" ]
), $HOME/.bashrc
的扩展来源。
由于Bash在调用时设置了$BASH_VERSION
,因此检查$BASH_VERSION
是否具有非零长度是确定文件本身是否由Bash实例提供的有效方法。
这就是为什么当在Ubuntu上调用Bash作为登录shell时,包含存储在~/.bashrc
中的用户设置(对于其他发行版不一定如此); 当作为登录shell调用时,Bash本身只会提供~/.profile
,这是一种绕过它的方法;
if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi
这部分检查$HOME/bin
的扩展是否存在并且是一个目录( if [ -d "$HOME/bin" ]
),如果是这种情况,则将$HOME/bin
的扩展预先设置为$PATH
的当前值( PATH="$HOME/bin:$PATH"
; $HOME
通常设置为用户的主目录)。
这样做是为了使$HOME/bin
扩展中存在的潜在可执行文件/脚本优先于$PATH
包含的其他路径中存在的可执行文件/脚本。