Apple announced changes to the default shell for macOS 10.15:
The current beta version of macOS 10.15 only affects newly created users.
For years now, Apple have appeared to avoid any tools that are covered by the GPL v3 Licence as well as remove any that were in use over time. Bash is one of these. In the early releases of 10.x Apple initially used tcsh shell as default, but soon moved to bash; so this is not the first time Apple have made a change of this kind.
In order to avoid newer versions of bash covered by GPL v3 licensing, it can be seen how old bash is on a macOS device:
Run the same command on a modern Linux system, e.g. the FileWave Linux Server Appliance and you will see a much newer version:
GPL v3 licence has implications for Apple. zsh is licensed under MIT, which does not involve these same implications.
Specifying the shell
The first line of a script should indicate which shell is used when a script runs.
Example, for bash this could typically be either of the following (this is known as the 'shebang'):
By providing this, the script will run from a shell of the specified type. Any scripts created should have this set. If this is not set, then the script will run in the shell type that is currently set for that shell's session. Apple's changes will have an impact on any scripts not specified by default. Best practice is to always add the shebang at the beginning of any script to ensure expected behaviour.
Bash vs zsh
Bash and zsh are very similar, but there are some differences which may interfere with scripts that were written for bash, but are then run as zsh. Scripts should therefore be analysed for behaviour if the shell type of the script is changed.
The first item of an array differs when being referenced:
- bash reference of first item in an array: index 0
- zsh reference of first item in an array: index 1
There is also a difference in deleting items from an array. The following produce the same output from the same original array, but note differences on the item being indexed and the method of removal:
Word splitting on variable expansion differs between bash and zsh. For example, bash will print the following, one line per word, whilst zsh will print the whole variable as one line. Note also, that bash, by default, will not expand aliases when the shell is not interactive, unlike zsh.
zsh does have the ability to set an option to change this behaviour, but consider converting to an array instead.
Apple has chosen zsh over bash, since the overlap on script compatibility is high. However, as seen there can be differences and so it is prudent to check all scripts for behaviour. The above are just examples; other differences may be experienced and will require addressing appropriately.