我通过执行创建了一个新用户
sudo useradd -m harry
当我尝试用“su - harry”替换用户时,我能看到的一切都是“$”(美元)符号,自动完成功能不起作用,并且 shell 内置函数(例如源代码)不可用。
我检查了 .bashrc 和 .profile 并检测到 .bashrc 没有被获取,因为 $BASH_VERSION 没有设置。
.profile 中的代码如下所示:
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Run Code Online (Sandbox Code Playgroud)
该命令不echo $BASH_VERSION
返回任何内容。
$ echo $BASH_VERSION
$
Run Code Online (Sandbox Code Playgroud)
Shell 内置函数(源 .bashrc、. .bashrc)也不起作用。
SHELL 变量值是“/bin/sh”,它是破折号的别名。我将其更改为 /bin/bash(导出 SHELL=/bin/bash)但它没有任何效果。
当我在 .profile 中硬编码“. .bashrc”(当然,只是为了检查它是否有效)我收到几个错误:
admin@host:~$ sudo su - harry
-su: 13: /home/harry/.bashrc: shopt: not found
-su: 21: /home/harry/.bashrc: shopt: not found
-su: 105: /home/harry/.bashrc: shopt: not found
-su: 28: /etc/bash_completion: [[: not found
-su: 34: /etc/bash_completion: [[: not found
-su: 51: /etc/bash_completion: Bad substitution
\[\e]0;\u@\h: \w\a\]\u@\h:\w$
Run Code Online (Sandbox Code Playgroud)
任何想法如何解决它?
先感谢您。杰佩特科
该用户的外壳是/bin/sh
. 这是一个较小的 shell,它使用的资源比 bash 少,但提供的编程功能较少,几乎没有交互功能。
运行sudo chsh -s /bin/bash harry
以将用户的登录 shell 更改为 bash。这会更改用户条目/etc/passwd
(不要直接编辑该文件,除非您知道自己在做什么)。
设置SHELL
环境变量告诉应用程序运行不同的 shell,但对当前运行的 shell 没有影响。