What are the downsides of putting GNU coreutills first in ${PATH}?

I'm coming from Linux to macOS, and many of my scripts assume GNU versions of the utils provided in GNU coreutils.

I could just put the GNU coreutils bin directory in earlier in $PATH than /bin.

Is this commonly done? If I do it, what downsides/breakages should I expect in future?


Solution 1:

It will break any script which expects BSD-style utilities (different arguments, partially different functionality)

But you can install coreutils with Homebrew or Macports which will give them a g prefix (gcp etc). And then adapt your scripts to use those (depending on the platform they run).

Solution 2:

While using un-prefixed coreutils has the potential to break any script expecting BSD-style programs, I have been using un-prefixed coreutils for almost 8 years now, and I've never run into a single issue. Given the anecdotal nature of that experience report you should take it with a grain of salt, but my experience has been that the reported dangers of un-prefixing are overblown.

Solution 3:

I think it's safer to not have the GNU coreutils first in PATH, but I don't really know macOS.

A relatively easy way to get your existing scripts to use GNU coreutils is to redefine PATH in the beginning of each script.

export PATH=/path/to/coreutils:$PATH

This way you won't have to rename (or add full path) to all of the commands in a script.