我工作的 unix 系统管理员不愿意让我将登录 shell 从 更改ksh
为bash
.他给出了各种借口,最有趣的是,因为他们编写了所有脚本,ksh
如果我尝试运行它们,它们将无法工作。我不知道他从哪里得到这些想法,但既然我无法说服他,我还有其他选择吗?
(chsh
安装在这些计算机上,但我们使用公钥/私钥对进行登录,并且我没有任何密码,因此当chsh
提示我输入密码时,我没有什么可提供的。)
答案1
当您登录时,~/.profile
登录 shell(为您提供 ksh)会读取该文件。您可以指示该登录 shell 将其自身替换为 bash。您应该采取一些预防措施:
- 仅当登录 shell 是交互式时才替换它。这很重要:否则,以图形模式登录可能无法正常工作(这取决于系统:
~/.profile
通过 xdm 或类似方式登录时,某些系统(但不是所有系统)会读取),并且诸如此类的习惯用法ssh foo '. ~/.profile; mycommand'
将失败。 - 检查 bash 是否可用,以便在可执行文件由于某种原因不存在时您仍然可以登录。
您可以选择是否将 bash 作为登录 shell 运行。使其成为登录 shell 的唯一主要区别是它会加载~/.bash_profile
或~/.profile
.因此,如果您将 bash 作为登录 shell 运行,请非常小心,~/.bash_profile
或者注意不要从~/.profile
.通过 bash 而不是 ksh执行并没有真正的优势~/.profile
,所以我建议不要这样做。
还将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
答案2
这有点麻烦,但是您可以通过在主目录中bash
创建一个文件来使其成为登录时使用的 shell ,其中包含.profile
SHELL=`type -P bash`
exec bash -l
这将导致ksh
会话被替换为bash
会话。您不必像每次登录时手动启动新会话那样键入exit
(或) 两次。然后键入^D
bash
echo $SHELL
甚至会返回到 的路径bash
。
答案3
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
答案4
索拉里斯:
usermod -s /bin/bash root