无法通过 MacPorts 在 Mac 中更新我的 Bash

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/791227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:50:03  来源:igfitidea点击:

Unable to update my Bash in Mac by MacPorts

macosbashmacports

提问by Léo Léopold Hertz ??

I updated unsuccessfully my Bash to 3.2.48 by MacPorts.

我通过 MacPorts 将 Bash 更新到 3.2.48 失败。

It seems that I do not have it active, since I get

似乎我没有激活它,因为我得到了

echo $BASH_VERSION
3.2.17(1)-release

How can you make the newest Bash activesuch that I get it for my login shell?

您如何使最新的 Bash 处于活动状态,以便我在登录 shell 中获得它?

回答by Nicholas Riley

Run the following code, for instance to change your shell to the newest Bash installed by MacPorts

运行以下代码,例如将您的 shell 更改为 MacPorts 安装的最新 Bash

chsh -s /opt/local/bin/bash

If that gives you the message,

如果这给了你信息,

"non-standard shell"

non-standard shell

you will need to add

你需要添加

/opt/local/bin/bash

to

/etc/shells

Note that /etc/shellsis just a text file, so you can edit it directly if you authenticate as root. You can programmatically change it by the command

请注意,这/etc/shells只是一个文本文件,因此如果您以 root 身份进行身份验证,则可以直接编辑它。您可以通过命令以编程方式更改它

sudo -s
Password:
# echo /opt/local/bin/bash >> /etc/shells

If your first chsh command failed, run it now again if you managed to change the above file.

如果您的第一个 chsh 命令失败,如果您设法更改了上述文件,请立即再次运行它。

回答by segy

I'm guessing it's installed but not being used as your login shell.

我猜它已安装但未用作您的登录外壳。

You can change the shell using dscl on the command line.

您可以在命令行上使用 dscl 更改外壳。

At the dscl prompt type the following:

在 dscl 提示符下键入以下内容:

list Local/Default/Users
read Local/Default/Users/<your username here>
change Local/Default/Users/<your username here> UserShell /bin/bash /opt/local/bin/bash

I have another example of dscl use on my blogif it helps.

如果有帮助,我的博客上还有另一个使用 dscl 的示例。

回答by Uwe Günther

You can switch your login shell, from your existing Mac OS X login shell (by default its /bin/bashshipped with Mac OS X), to MacPorts /opt/local/bin/bashjust by using the following shell script:

只需使用以下 shell 脚本,您就可以将登录 shell 从现有的 Mac OS X 登录 shell(默认情况下/bin/bash随 Mac OS X 一起提供)切换到 MacPorts /opt/local/bin/bash

#!/opt/local/bin/bash
if [ `grep /opt/local/bin/bash /etc/shells` ]; 
then 
    echo /opt/local/bin/bash | chsh -s /opt/local/bin/bash;     
else 
    echo /opt/local/bin/bash | sudo tee -a /etc/shells; 
    chsh -s /opt/local/bin/bash; 
fi