An Interest In:
Web News this Week
- April 3, 2024
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
Differences Between MacOS and Linux Scripting
Photo by Sharon McCutcheon on Unsplash
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), 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.
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 definition 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?
Original Link: https://dev.to/aghost7/differences-between-macos-and-linux-scripting-74d
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To