I often hear people saying MacOS and Linux are similar. I would like to propose that they are in fact very different.
But why does this matter? Well, for one, I write a lot of code for CI (Continuous Integration). The differences are big enough to make it challenging to re-use more complex scripts locally and in CI.
MacOS recently changed its default shell to zsh. Before this, it was using a decade old release of bash.
Now, nothing is stopping you from installing the latest version of bash. If you're writing scripts for your team it is unlikely you will have much control over that however.
This is probably the most significant difference with MacOS and Linux when it comes to scripting automation. Most people on Mac rely on Homebrew, while most servers on Linux use apt. Not only is it different to install packages, but so is adding new software sources.
Since Docker for Mac runs in a virtual machine (using linuxkit), there are significant differences with running containers on it.
Volumes (bind mounts) have poorer performance. This may limit how many things you can throw at compose if your project is a large codebase.
File permissions map differently from the container to the host. Linux may use subordinate uids and gids, whilst MacOS maps all users to one uid/gid on the host.
MacOS uses a different implementation of find. Linux has a couple of extra options, and the search path is optional.
netstat on Linux is a different implementation altogether. For certain tasks you will need to use
lsof when on MacOS. The output for
lsof is also different, so you will need to implement different parsing code for each operating system.
ifconfig is deprecated on Linux. It is recommended to write new scripts with
ip instead. Since MacOS doesn't have
ip, you're stuck with writing an implementation for each operating system.
xargs, which is used for piping arguments to another command, works slightly differently on MacOS. If the previous command has no output,
xargs on MacOS won't run the command.
MacOS uses launchd, which accepts an xml configuration for the definition of new services. Most modern Linux distributions rely on systemd, which has a INI-like configuration format.
Did you run into other discrepancies between the two operating systems? What are some of the best practices you follow to write portable scripts?