Sujet : Re: Numerically sorted arguments (in shell)
De : geoff (at) *nospam* clare.See-My-Signature.invalid (Geoff Clare)
Groupes : comp.unix.shellDate : 18. Jun 2024, 13:32:06
Autres entêtes
Message-ID : <6bb8kk-pks.ln1@ID-313840.user.individual.net>
References : 1 2 3 4 5 6
User-Agent : Pan/0.154 (Izium; 517acf4)
Helmut Waitzmann wrote:
If ‘p_sort’ is designed to output the sorted file names separated
by an ASCII NUL character rather than a newline then, using the
GNU version of ‘xargs’, one can feed that output into ‘xargs’:
{
p_sort P*.HTM 3<&- |
xargs --null --no-run-if-empty -- sh -c \
'exec 0<&3 3<&- "$@"' sh \
viewer
} 3<&0
NUL as a record separator is also supported by several other versions
of xargs, and it is in the recently released POSIX.1-2024 standard.
In all of those it is specified with -0, so using -0 is more
portable than the GNU-specific --null.
POSIX.1-2024 also has -r although I think that's not as widely
supported in current xargs implementations as -0. It should become
better supported over time, though, so again I would suggest using -r
rather than --no-run-if-empty for better future portability.
-- Geoff Clare <netnews@gclare.org.uk>