今日SSH连接测试机时,欢迎界面提示如下内容:
1
2
3
4
5
|
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前十行如下
1
2
3
4
5
6
7
8
9
10
11
|
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
|
经与另外一台机器对比后发现,第一、三、九行少了一个"#"号,添加完后上述错误提示即消失。
1
2
3
4
5
6
7
8
9
10
11
|
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
|
1
2
3
4
5
6
7
|
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文件中一般会有下面的代码:
1
2
3
|
if
[ -f ~/.bashrc ] ;
then
. .
/bashrc
fi
|
~/.bashrc中,一般还会有以下代码:
1
2
3
|
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:写这篇博客时房间已停电,吼吼吼,不过正好练习了下盲打。
本文转自 xoyabc 51CTO博客,原文链接:http://blog.51cto.com/xoyabc/1679412,如需转载请自行联系原作者