Upgrading Bash on MacOS

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@obivankenobi·
0.000 HBD
Upgrading Bash on MacOS
![Bash Logo](https://i.imgur.com/GH3T1P6.png)
Tech Tuesday Time.

Apple doesn't support GPLv3 thus [bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)) won't be updated due to [licensing](https://apple.stackexchange.com/questions/193411/update-bash-to-version-4-0-on-osx/292760). 
```
$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.
```
<br>However [homebrew](https://brew.sh/) has it as a normal package. Time to install it.
```
$ brew install bash
```
<br>Now lets add it to the list of shells.
```
$ sudo echo /usr/local/bin/bash >> /etc/shells
```
<br>I even rearranged it to make the list look neater.
```
$ cat /etc/shells 
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/usr/local/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
```
<br>Last but not least, lets change the default system shell using *chsh*
```
$ sudo chsh -s /usr/local/bin/bash
```
<br>Verifying that the new path is updated in the apple user configuration database:
```
$ dscl . -read /Users/$USER UserShell
UserShell: /usr/local/bin/bash
```
<br>All is looking good!
```
$ echo $BASH_VERSION
5.0.2(1)-release

$ bash --version 
GNU bash, version 5.0.3(1)-release (x86_64-apple-darwin18.2.0)
Copyright (C) 2019 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.
```
#### Bonus Hack - Bash auto-completion
What's the point of installing bash 4.x and later versions if you can't enjoy extra auto-completion.
Lets install the latest auto-completion v2 that is compatible with bash 4.x or later.
```
$ brew install bash-completion@2
```
<br>Notice that during the installation you are advised to do the following:
```
==> bash-completion@2
Add the following to your ~/.bash_profile:
  [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
```
<br>I'm adding what the installer suggests to my .profile file. In your case it might be .bash_profile.
```
$ echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >> .profile
```
<br>Now type *rsync --* [Tab] for example and see what happens. Enjoy!

##### TL;DR
```
1) brew install bash
2) sudo echo /usr/local/bin/bash >> /etc/shells
3) sudo chsh -s /usr/local/bin/bash
4) dscl . -read /Users/$USER UserShell
5) echo $BASH_VERSION
```
<br>Bonus:
```
1) brew install bash-completion@2
2) echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >> .profile
```
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,