Macos – What’s at Risk with Switching to ZSH

bashmacoszsh

Most advice for Mac is written assuming you use the Bash shell. If I switch to zsh, how incompatible do I become with current Bash scripts that I have on my system, and advice people on SU give me?

Does the #!/bin/sh line at the beginning of my scripts help?

Edit: Irrelevant to the question is why I want to do this. Better tab-completion. I just tried out zsh putting in a login script as suggested here and I'm absolutely blown away.

Best Answer

The shebang line you show means to run the script using the Bourne shell (or another shell in compatibility mode). Those scripts will likely continue to run using the same shell they are now if you switch to zsh as your interactive shell. The only way that will change is if you link sh to zsh, but that shouldn't change the functionality.

You will find a certain amount of compatibility between zsh and Bash when used as your login shell or when writing scripts specifically calling for one or the other using shebang lines like:

#!/usr/bin/bash

or

#!/usr/bin/zsh

However, there are a lot of things that zsh does differently or that Bash can't do at all. Bash is much more widely used, so there are fewer people familiar with the intricacies of zsh. Information on it is widely available, though. Also, you'll find that there's more than adequate help available here.

You'll find that for writing scripts either shell is considerably more powerful than the Bourne shell (sh), but at the expense of portability. Also, since Bash is more widely used than zsh, its scripts are relatively more portable.