问题:用ssh登录终端后发现.bashrc里的脚本并没有被执行
原因1:
默认的shell非bash
解决方法:
查看:
# echo $SHELL
若输出结果不是 /bin/bash (通常是/bin/sh),就需要更改为bash。
方法1:更改命令:
# chsh
chsh Password:
Changing the login shell forguojun Enter the newvalue, or press ENTER forthe default
Login Shell [/bin/sh]: /bin/bash
方法2:修改/etc/passwd
# sudo vim /etc/passwd
xiehui:x:1002:1002::/home/xiehui:/bin/bash
原因2
若非原因1无效或者echo $SHELL的输出为/bin/bash。
通常这种情况下是因为profile文件出了问题
解决方法:
不存在:通过创建用户获取文件
# sudo useradd -R get_profile
# cp /home/get_profile/.profile ~/
# sudo userdel -R get_profile
# rm -rf /home/get_profile
文件存在问题:添加执行bashrc命令
# vim ~/.profile
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi