Differences Between MacOS and Linux Scripting
Tags: devops, docker, linux, macos
Published: 2020-10-22 00:00:33

---
title: Differences Between MacOS and Linux Scripting
published: true
description: 
tags: devops, docker, linux, macos
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/8m89oihwd1ujxxdqmueb.jpg
---
_<span>Photo by <a href="https://unsplash.com/@sharonmccutcheon?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sharon McCutcheon</a> on <a href="https://unsplash.com/s/photos/document?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>_

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.

## The Shell
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.

## Package Manager
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.

## Docker
Since Docker for Mac runs in a virtual machine (using [linuxkit](https://github.com/linuxkit/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](https://www.man7.org/linux/man-pages/man5/subuid.5.html) and gids, whilst MacOS maps all users to one uid/gid on the host.

## find
MacOS uses a different implementation of find. Linux has a couple of extra options, and the search path is optional.

## netstat
Similarly to `find`, `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
`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
`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.

## init
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.

## In Closing
Did you run into other discrepancies between the two operating systems? What are some of the best practices you follow to write portable scripts?