2009-09-25 12:03:09 +0000 2009-09-25 12:03:09 +0000
107
107
Advertisement

如何让Bash成为Ubuntu上的默认shell?

Advertisement

我在我的主目录中有一个.bash_profile,但它在登录时没有被运行。如果我做以下操作,那么事情似乎和我期望的一样:

ssh myhost
bash
source ~/.bash_profile

但通常这一切都发生在登录时。有什么想法?

Advertisement
Advertisement

答案 (8)

176
176
176
2009-09-25 12:08:58 +0000

使用:

chsh

输入你的密码并说明你要使用的shell的路径。

Bash的路径是/bin/bash。对于Zsh,则是/usr/bin/zsh

37
37
37
2009-09-25 12:09:20 +0000

除了akira的回答,你也可以编辑你的 /etc/passwd 文件来指定你的默认shell。

你会发现有这样一行:

john:x:1000:1000:john,,,:/home/john:/bin/sh

shell是在最后指定的。

4
Advertisement
4
4
2009-09-25 12:14:23 +0000
Advertisement

你可以检查一下你的终端程序。它可能被配置为运行/bin/sh而不是/bin/bash

Bash只在登录会话中执行.bash/profile。.bashrc是为所有bash会话执行的,而不仅仅是登录会话。试着从.bashrc中获取.bash_profile (避免循环依赖!)或者配置你的终端程序作为shell程序运行/bin/bash -l。

4
4
4
2018-01-25 18:44:30 +0000

启用bash。

$ /bin/bash

更改用户的shell。

$ sudo usermod -s /bin/bash username

where:

-s, --shell SHELL new login shell for the user account
2
Advertisement
2
2
2010-06-01 11:40:25 +0000
Advertisement

一个替代方法是将你的启动脚本改名为.profile。这个文件被大多数Unix shell

1
1
1
2019-11-17 19:17:11 +0000

如果你在/etc/passwd文件中看不到你的用户名[当你的系统由其他域控制时,例如在IT公司,这种情况就会出现],或者它显示 “未找到用户",并带有chsh选项,下面的过程可能会帮助你。

下面的技巧背后的逻辑 -> 在Ubuntu上,/bin/sh是dash。你可以把你的系统切换到使用bash。在Ubuntu上,/bin/sh是dash的符号链接。要改变它,运行

sudo dpkg-reconfigure dash

然后按No切换到bash

现在,进入终端-/>编辑-/>首选项-/>命令,然后勾选语句

以登录shell身份运行命令

就这样。

1
Advertisement
1
1
2019-06-27 13:29:35 +0000
Advertisement

要使任何 shell 成为你的默认值,首先通过查看 /etc/shells 的内容来验证它是否在你的计算机上安装和识别。

$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/fish

然后使用chsh改变你的shell:

$ sudo chsh -s /usr/bin/bash $(whoami) # or sudo chsh -s /bin/bash $(whoami)

参考资料

  1. https://linux.die.net/man/1/cat
  2. https://linux.die.net/man/1/whoami
  3. https://linux.die.net/man/5/shells
  4. https://linux.die.net/man/1/chsh 4.
0
0
0
2018-09-15 19:37:41 +0000

你的问题中没有足够的信息让我确定,但我以前也遇到过同样的问题。假设你已经在你的密码输入中设置了/bin/bash,可能是你的终端启动方式的问题。

如果你试图启动一个GUI终端,比如gnome-terminal你可能希望shell能读取你的bash启动文件。然而,这在Ubuntu上不会发生,也许其他系统默认情况下也不会。

我在Ubuntu上解决这个问题的方法是编辑gnome-terminal偏好设置,并将启动命令设置为bash -l-l--login的缩写。这告诉bash以登录shell的方式启动,这将导致它加载启动脚本,就像你通过ssh登录时一样。

我相信这样做有一个很好的理由,但我发现这很令人惊讶,而且我在linux、cywgin和macos系统中共享相同的配置文件,所以我觉得很烦。

Advertisement

相关问题

19
12
11
6
3
Advertisement