Mic*_*ant 27 macos bash shell homebrew default
当我这样做时,brew upgrade我看到我确实有更新的版本.我怎么用呢?
$ bash -version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
$ brew upgrade bash
Error: bash-4.2.45 already installed
$ which bash
/bin/bash
Run Code Online (Sandbox Code Playgroud)
我确实看到了
/usr/local/Cellar/bash/4.2.45/bin
Run Code Online (Sandbox Code Playgroud)
但是当我这样做的时候
$ /usr/local/Cellar/bash/4.2.45/bin/bash
Run Code Online (Sandbox Code Playgroud)
我还在
$ bash -version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
08:06:45 mdurrant w89123148q1 /usr/local/Cellar/bash/4.2.45/bin master
Run Code Online (Sandbox Code Playgroud)
内容/etc/shells是:
/usr/local/Cellar/bash/4.2.45/bin/bash  # (I added this)
/usr/local/bin/bash
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
Run Code Online (Sandbox Code Playgroud)
chsh似乎没有按照我的意愿行事:
$ chsh -s /usr/local/Cellar/bash/4.2.45/bin/bash
Changing shell for mdurrant.
Password for mdurrant:
chsh: /usr/local/Cellar/bash/4.2.45/bin/bash: non-standard shell
$ bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)
我有这里的文件:
$ l /usr/local/Cellar/bash/4.2.45/bin/bash
-r-xr-xr-x  1 mdurrant  admin  699688 Apr 14 19:54 /usr/local/Cellar/bash/4.2.45/bin/bash*
Run Code Online (Sandbox Code Playgroud)
我还没有实际看到新的bash版本,无论如何,我尝试以交互方式调用它.
$ echo $BASH_VERSION 节目  
3.2.51(1)-release
Run Code Online (Sandbox Code Playgroud)
我试过用dscl做了
> change Local/Default/Users/mdurrant UserShell /bin/bash /usr/local/Cellar/bash/4.2.45/bin/bash
Run Code Online (Sandbox Code Playgroud)
但得到了
<main> attribute status: eDSAttributeNotFound
<dscl_cmd> DS Error: -14134 (eDSAttributeNotFound)
Run Code Online (Sandbox Code Playgroud)
现在列表显示
> UserShell: /usr/local/Cellar/bash/4.2.45/bin/bash
Run Code Online (Sandbox Code Playgroud)
    mkl*_*nt0 45
bash --version(或bash -version)不会报告CURRENT shell的版本,而是报告首先出现的bash可执行文件的版本$PATH.  
[注:OSX 10.10(约塞米蒂)是第一个版本OSX其中/usr/local/bin放置BEFORE系统路径,例如/bin在$PATH.系统路径最高可达10.9.因此,当OP询问他的问题时,bash --version报告了SYSTEM的bash的版本(/bin/bash),而不是Homebrew安装的版本(/usr/local/bin/bash)]
如果您想知道当前Bash shell的版本,请使用:
echo $BASH_VERSION
Run Code Online (Sandbox Code Playgroud)
换句话说:您的shell可能已经成功更改 - 您的测试存在缺陷.
您可以使用chsh更改当前用户的shell,如下所示:  
[更新:切换到使用/usr/local/bin/bash而不是特定的版本化路径/usr/local/Cellar/bash/<version>/bin/bash,因为Homebrew会自动使符号链接/usr/local/bin/bash指向最新安装的版本.给@drevicko的帽子提示.]
 # First, add the new shell to the list of allowed shells.
sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells'
 # Change to the new shell.
chsh -s /usr/local/bin/bash 
Run Code Online (Sandbox Code Playgroud)
请注意,系统会提示您输入密码.
您从该点创建的任何终端选项卡/窗口都将使用新shell.
来自@bmike的额外提示:如果您想立即用新shell的实例替换当前的 shell实例,请运行:
exec su - $USER  # instantly replaces current shell with an instance of the new shell
Run Code Online (Sandbox Code Playgroud)
请注意,系统会再次提示您输入密码.
或者,使用dscl -  OSX目录服务CLI  - 来更改当前用户的shell; 然而,这更麻烦.
要检查当前用户的shell,请使用:
dscl . -read /Users/$USER UserShell  # e.g. (default): 'UserShell: /bin/bash'
Run Code Online (Sandbox Code Playgroud)
或者更简单地说,echo $SHELL它只输出文件路径(例如/bin/bash).
要将当前用户的shell 更改为,例如/usr/local/bin/bash,请使用:
sudo dscl . -change /Users/$USER UserShell /bin/bash /usr/local/bin/bash
Run Code Online (Sandbox Code Playgroud)
注意:
/etc/shells的交互使用,但在评论中/etc/shells状态Ftpd will not allow users to connect who are not using one of these shells.Terminal.app(或iTerm.app)以使更改生效 - 验证新shell echo $BASH_VERSION- 不需要重新启动.OP遇到的错误说明:
chsh: /usr/local/Cellar/bash/4.2.45/bin/bash: non-standard shell意味着/usr/local/Cellar/bash/4.2.45/bin/bash- 不是 - 还没有,或者没有这种确切的形式 - 列在/etc/shells.<main> attribute status: eDSAttributeNotFound:dscl当为-change命令指定的倒数第二个(倒数第二个)参数与当前属性值不匹配时,会发生此错误- 它是 - 确实很奇怪 - 要求指定属性的当前值以便更改它.虽然这个问题表明这两个条件都得到满足,但我怀疑由于实验,它们在正确的时间没有得到满足.