Please enable JavaScript eh!

 Web Mechanic 

Bash Scripting

 bash or zsh 

Just to confuse things a bit, if your macOS computer is Catalina (10.15) or newer, then it is set up to use a shell called zsh by default instead of bash.

To find out which shell you are currently set up to use, open Terminal and enter:

echo $SHELL

My computer responds with

/usr/local/bin/bash

$SHELL is an environment variable, meaning it holds information about your environment (system). There are several other system variables which we will discover.

The version of bash that is installed with macOS is not kept up-to-date, but there are ways to get the current version, which I strongly reccommend. I use HomeBrew. My bash version at the time of this writing is 5.2.26(1).

bash is not owned or controlled by Apple. It is developed and owned by Free Software Foundation, Inc., as indicated below.

bash --version
GNU bash, version 5.2.26(1)-release (aarch64-apple-darwin23.2.0)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

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

 Setting bash as default 

Apple has set different default shells over the years. For example Panther used tcsh. Prior to Catalina bash was the default, then zsh was the default.

There are several different shells which come with macOS:

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.

/usr/local/bin/bash
/opt/homebrew/Cellar/bash/5.2.26/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

Follow the instructions in the HomeBrew installation, which should show you how to put the correct location into your path.

With Sonoma (and earlier), setting the default shell is done easily with System Settings.

  1. Open System Settings
  2. Click 'Users & Groups' to open
  3. Right-click on the user you want to edit
  4. Click the 'Advanced Options' button
  5. Enter the password for that user
  6. Under 'Login shell' pick '/usr/local/bin/bash'
  7. Click OK to close this window
  8. Close the System Settings window
You MUST close (quit) your current Terminal session,
and start it again for any new shell to take affect

If you've done this correctly, you should be using a current bash shell.

echo $SHELL
should tell which version is now active, and it should be higher than 4.0.

 Some links for further elucidation: 

Linux Scripting Series
Linux Command Line
Ryans Tutorials
Apple Discussions
Bash Cheat Sheet
StackExchange
zsh FAQ
StackAbuse
• man bash
  If you are familiar with man, in Terminal run the command man bash
  This is a very concise, technical reference 'manual' / guide to running bash and some internal commands. It is NOT a programming tutorial, but better suited to settling arguments.

This site is strictly about the bash shell. A web search for 'zsh' will bring up lots of sources for that.

Fundamentals