Answers:
登录时,~/.profile登录外壳程序(适合您的ksh)读取该文件。您可以指示该登录Shell替换为bash。您应该采取一些预防措施:
~/.profile通过xdm或类似方式登录时,某些(但不是全部)系统会读取),并且诸如此类的习惯用法ssh foo '. ~/.profile; mycommand'会失败。您可以选择是否将bash作为登录shell运行。使它成为登录shell的唯一主要区别是它将加载~/.bash_profile或~/.profile。因此,如果您将bash作为登录shell运行,请非常小心地使用a ~/.bash_profile或注意不要从中递归执行bash ~/.profile。~/.profile由bash而不是ksh执行并没有真正的优势,所以我建议不要这样做。
SHELL还将环境变量设置为bash,以便终端仿真器之类的程序将调用该shell。
这是切换到bash的代码。将其放在的末尾~/.profile。
case $- in
*i*)
# Interactive session. Try switching to bash.
if [ -z "$BASH" ]; then # do nothing if running under bash already
bash=$(command -v bash)
if [ -x "$bash" ]; then
export SHELL="$bash"
exec "$bash"
fi
fi
esac
.profile仅适用于登录shell(根据OP的需要)。我使用Windows 10的远程桌面连接登录Linux工作站,然后在gnome中打开Terminal。我想zsh在系统管理员给我的同时给我bash。在这种情况下,我必须添加.bashrc而不是的代码段.profile。
这有点麻烦,但是您可以bash通过.profile在主目录中创建一个文件来使它成为登录时使用的shell ,其中包含
SHELL=`type -P bash`
exec bash -l
这将导致ksh会话替换为bash会话。您无需两次输入exit(或^D),就像bash每次登录时手动启动一个新会话一样。
echo $SHELL
甚至会返回的路径bash。
exec bash -l。
bash也不会阅读.profile从而产生无限循环吗?我同意exec bash您想要的是什么,但是您需要确保仅对登录ksh进行操作,因此需要一些if语句!
~/.bash_profile或~/.bash_login
Giles的答案在执行bash时应添加-l标志,以便所有登录配置文件脚本都将来自新的bash shell。(例如,RHEL上/etc/profile.d/中的任何内容)。该脚本应为:
case $- in
*i*)
# Interactive session. Try switching to bash.
if [ -z "$BASH" ]; then # do nothing if running under bash already
bash=$(command -v bash)
if [ -x "$bash" ]; then
export SHELL="$bash"
exec "$bash" -l
fi
fi
esac
-l选项吗?我已经使用了几个月,没有任何问题。