今日SSH连接测试机时,欢迎界面提示如下内容:

Last login: Tue Jul 28 22:08:07 2015 from 10.241.10.7
欢迎回来
-bash: .bashrc: command not found
-bash: User: command not found
-bash: Source: command not found

.bashrc前十行如下

root@samba ~$cat -n .bashrc | head
     1    .bashrc
     2    
     3    User specific aliases and functions
     4    
     5    alias rm='rm -i'
     6    alias cp='cp -i'
     7    alias mv='mv -i'
     8    
     9    Source global definitions
    10    if [ -f /etc/bashrc ]; then

经与另外一台机器对比后发现,第一、三、九行少了一个"#"号,添加完后上述错误提示即消失。

root@samba ~$cat -n .bashrc | head
     1    #.bashrc
     2    
     3    #User specific aliases and functions
     4    
     5    alias rm='rm -i'
     6    alias cp='cp -i'
     7    alias mv='mv -i'
     8    
     9    #Source global definitions
    10    if [ -f /etc/bashrc ]; then
Connecting to 10.240.210.233:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Tue Jul 28 22:19:30 2015 from 10.241.10.7
欢迎回来
root@samba ~$

远程连接登陆Linux服务器时,/etc/profile、~/.bash_profile、~/.bashrc的启动顺序如下

首先启动 /etc/profile 文件,然后再启动用户目录下的 ~/.bash_profile。如果 ~/.bash_profile文件存在的话,一般还会执行 ~/.bashrc文件。因为在 ~/.bash_profile文件中一般会有下面的代码:

if [ -f ~/.bashrc ] ; then
. ./bashrc
fi

~/.bashrc中,一般还会有以下代码:

if [ -f /etc/bashrc ] ; then
. /bashrc
fi

所以,~/.bashrc会调用 /etc/bashrc文件。最后,在退出shell时,还会执行 ~/.bash_logout文件。

执行顺序为:/etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout


PS:写这篇博客时房间已停电,吼吼吼,不过正好练习了下盲打。