News for hackers. Stuff that matters.
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by yjftsjthsd-h on Saturday November 25, 2023 @11:59PM (#38419293)
Right; the coreutils built in to Darwin are BSD-derived, I was referring to a user installing the GNU versions over top of the OS proper.
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by n8henrie on Sunday November 26, 2023 @12:30AM (#38419399)
Yes, like I did first with homebrew and now with nix.
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by divbzero on Sunday November 26, 2023 @02:07AM (#38419777)
I bet many of us do this due to small differences between BSD and GNU coreutils. One that always gets me is:

  sed -i '' 's/foo/bar/g'  # BSD sed
  sed -i 's/foo/bar/g'     # GNU sed
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by jorams on Sunday November 26, 2023 @05:13AM (#38420523)
That is indeed an incredibly frustrating difference, because there is no version of it that works on both GNU and macOS. In practice I often end up using perl to do an in-place search-replace instead.
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by arp242 on Sunday November 26, 2023 @08:14AM (#38421349)
But "sed -i'' s/../../ FILE" will work on both, no? Or -i.orig if you want to keep a backup file?
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by jorams on Sunday November 26, 2023 @12:53PM (#38423477)
That does not work on macOS. "-i''" is the same as just a bare "-i", and it will then interpret the next argument as the backup suffix.
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by arp242 on Sunday November 26, 2023 @01:52PM (#38423931)
Oops yes, that should have been -i '' with a space. But I see now that GNU doesn't accept -i '', or even -i .orig. It MUST be without a space: "-i.orig". The reason for that I assume is there's no way to disambiguate:

  echo foo | sed -i pattern
  echo foo | sed -i .orig
But you can still use "-i.orig"; that should work on both. That will leave you with a .orig file to clean up, but arguably that's not a bad thing as -i can clobber files.
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by jcelerier on Sunday November 26, 2023 @05:52AM (#38420690)
It takes a second to install gnu coreutils with homebrew and make Macs barely useable
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by emmelaich on Sunday November 26, 2023 @07:06AM (#38421005)
Or just use Perl
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by DonHopkins on Sunday November 26, 2023 @07:13AM (#38421039)
As long as you're using stone knives, might as well throw in some bear skins.

https://www.youtube.com/watch?v=F226oWBHvvI

Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by emmelaich on Sunday November 26, 2023 @11:34PM (#38428092)
Fun! But honestly there's a place for Perl.

There's far less variance between Perls on different systems than there are for sed/awk/shell. So if you want performant portable code, Perl does better than all of those.

I'd never use Perl for a 'big' program these days but it still beats the crap out of the mess of sed/awk/bash/ksh/zsh.

Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by freedomben on Sunday November 26, 2023 @01:43PM (#38423856)
Apple has been threatening to remove perl for ages. One of these days they'll find the "courage" to do so and we'll need a better strategy.
Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by arp242 on Sunday November 26, 2023 @02:10PM (#38424062)
FreeBSD removed Perl from base ages ago, in FreeBSD 5 or 6. That went alright.

I don't even have it on my Linux system any more; for better or worse, fewer and fewer things use it.

Re:A peculiarity of the GNU Coreutils version of 'test' and '[' by dolni on Sunday November 26, 2023 @08:16PM (#38426980)
I much prefer Linux but having used Macs a few times for work, I absolutely cannot recommend making GNU coreutils the default option on Macs.

If you make GNU coreutils the first binaries in PATH, you can expect subtle, _very nasty_ issues.

The last one I encountered was `hostname` taking something like 5 seconds to run. Before that, there was some bug with GNU’s stty which I don’t remember the specifics of.