2

I have observed that there are often subtle and often annoying differences between the default versions of certain command line tools like paste and sed on modern distributions of Linux versus OSX. This leads to answers that do not work on OS X even though they will work on almost any Linux distribution.

So I wonder, is there a standard way to get the full set of OS X versions of the standard Unix tools on modern Linux distributions so we can test solutions for correct functionaity on OSX, without having a copy?

5
  • Why would you want the OSX version on linux and not the GNU version on OSX? Commented Jun 22, 2014 at 19:24
  • 2
    Apple publishes the source they use, so you could try compiling them. Commented Jun 22, 2014 at 19:25
  • That too would be a solution. Commented Jun 22, 2014 at 19:28
  • @hbdgaf I could either convince all users of osx to get the standard versions or I could get osx versions on my system and write answers that will help all of them on their existing systems. Commented Jun 22, 2014 at 19:39
  • Then it comes down to easy versus correct. Commented Jun 22, 2014 at 22:15

2 Answers 2

3

As mentioned in a comment, Apple makes the source code of its versions of these tools available. Many common commands are in the "shell_cmds" package, while paste and sed are in "text_cmds". You can get the source code and compile.

Virtually all of them work fine on Linux systems, although you often have to jump into the source and remove explicitly FreeBSD-specific tests, particularly the __FBSDID("..."); line which is in almost every file. I don't know of any distribution that packages those up. Many distributions do package BSD versions of some common tools, which are very close (often identical) to the OS X versions, although they don't usually include things like paste and sed. For example, Debian includes eight packages called bsdX (none of which have either of those commands). For Apple's versions specifically, or for the many tools that aren't included in those, they're not hard to build yourself when you need them from the instructions above.

All of that said, the common subset of GNU and BSD tools is the POSIX specification, where all the basic commands are defined. You can look up the paste command or sed and see which arguments it is guaranteed to accept everywhere. This is the "morally correct" way of writing portable code: both GNU tools and BSD tools have extensions, but if you stay within POSIX your code will work on both. So check that you're always using only POSIX arguments and then what you say should work on OS X and other systems equally.

1

While most unixy tools of OSX are open-source, the source code of many tools relies on library and kernel features that are not present on Linux (and that are not open-source, and that can't run on non-Apple hardware without extra effort and perhaps license violations). I doubt that you'd be able to run them on Linux without significant effort.

OSX's unix layer is ported from FreeBSD and many programs are very similar to the one in the FreeBSD release that was current at the time of the OSX release. You can run FreeBSD in a virtual machine and test things there. You can also run OpenBSD; OpenBSD is focused on security and far more conservative than FreeBSD when it comes to adopting new features. If you want to test scripts for portability, you can also install OpenIndiana, which is an open-source fork of Solaris based on the now-discontinued OpenSolaris edition. Since Solaris is System V-based, Solaris plus OpenBSD gives you a reasonably broad view of Unix portability.

You can also check the documentation of many Unix variants online:

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.