BASH_VERSINFO与bash --version显示的不同

时间:2018-04-25 18:00:03

标签: bash

我尝试从/usr/local/Cellar/bash/4.4.19/bin/bash复制到/usr/local/bin/bash,因为which bash显示/usr/local/bin/bash

~/cat /etc/shells
/usr/local/Cellar/bash/4.4.19/bin/bash

~/bash --version
GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin17.3.0)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


echo $BASH_VERSINFO
3

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

bash --version显示如果从PATH启动新shell,将运行的版本

因此,此版本与来自which bash的安装位置(如果未被别名/函数/等修改)或type bash(更准确地说)或与用于运行脚本的shell相关联与#!/usr/bin/env bash shebang。

$BASH_VERSINFO$BASH_VERSION显示正在运行的版本

因此,如果您的脚本中包含#!/bin/bash shebang,或者密码数据库指定/bin/bash作为其shell的用户的交互式shell脚本,/usr/local/bin/bash(或任何在PATH中较早的其他位置与当前的,未从PATH shell实例开始的目的无关。

要从脚本中的PATH启动shell,请将shebang更改为#!/usr/bin/env bash。要从交互式会话中启动指定的shell,请使用chsh更新帐户的设置。