brew install coreutils

This installs the GNU versions of common utils to your mac, or coreutils. MacOS comes with versions of these, but they are slightly different or out of date. You don’t want to fully replace the MacOS utils, so the GNU ones are all prefixed with g.

I think I initially found this because MacOS’s date function broke one of my scripts because it expected GNU date.