Funny how trying to fix one thing kind of snowballs...
In this combo patch: Have the configure script look for a sort(1), preferring gsort over sort, so that on OSes without GNU userlands, if the GNU coreutils package is installed, its version of sort is used - decorate in particular assumes GNU sort for a lot of its options. Also add a --sort-cmd option to datamash and decorate for specifying an alternative at runtime.
Shell escape/quote the strings printed by decorate's --print-sort-args option when needed, and the sort command passed to popen() in datamash. Also gets rid of an existing arbitrary 1024 character limit on that in datamash.
In decorate, when using the NetBSD /usr/bin/sort, add -S to its options to make it use an unstable sort (Unlike every other sort(1), it's stable by default, which was breaking some tests).