DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
What's in store for DevOps in 2023? Hear from the experts in our "DZone 2023 Preview: DevOps Edition" on Fri, Jan 27!
Save your seat

Upgrading to Bash 4 on MacOS [Snippet]

Need to access those shiny features in Bash 4 from your Mac? Look at how to quickly and easily upgrade from Bash 3.

Rob Allen user avatar by
Rob Allen
·
Dec. 20, 18 · Tutorial
Like (3)
Save
Tweet
Share
15.31K Views

Join the DZone community and get the full member experience.

Join For Free

Incredibly, macOS Mojave comes with Bash 3.22 by default still. Apparently this is due to licensing reasons, however Bash 4 has lots of lovely features including associative arrays that I’d like use. Hence, after reading on the internet for a bit, I’ve installed it on my Mac. This turned out to require just 3 commands:

$ brew install bash
$ sudo bash -c 'echo /usr/local/bin/bash >> /etc/shells' 
$ chsh -s /usr/local/bin/bash

Close the terminal and open a new one, which now has Bash 4!

Bash4

Using Bash 4 in Scripts

Any script that starts with #!/bin/bash will continue to use Bash 3, so we use env in the same way as we do with PHP, Ruby, or Python scripts and start our Bash script files with:

#!/usr/bin/env bash

This will now use Bash 4 when you run the script interactively.

Bash (Unix shell) MacOS

Published at DZone with permission of Rob Allen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Microservices Discovery With Eureka
  • What Is a Kubernetes CI/CD Pipeline?
  • Better Performance and Security by Monitoring Logs, Metrics, and More
  • Top 10 Secure Coding Practices Every Developer Should Know

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: