Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Emulating 'find's print0...

On Wed, Nov 23, 2016 at 8:24 AM,  <Meino.Cramer@xxxxxx> wrote:
> Hi,
> cat-ting a list of file like so
>     cat files.txt | xargs md5sum | sort | .........
> fails, if a files name contains blanks.
> The tool find circumvent this by using print0
> and xargs understands this via -0.
> But I dont want to use find in this case, since the
> list of files (files.txt) are hand made and a manual
> selection of files.
> Is there any way to emulate "-print0" efficiently
> (that is: without accessing the drive again) ?

If you use a reasonable version of xargs, you can specify -d\\n to
only split on newlines. (POSIX xargs doesn't have it, but then again,
POSIX xargs is almost impossible to use safely).

Some examples:
% print -l "one line" "another line" | xargs printf %s\\n

% print -l "one'line" "another line" | xargs printf %s\\n
xargs: unmatched single quote; by default quotes are special to xargs
unless you use the -0 option

% print -l "one'line" "another line" | xargs -d\\n printf %s\\n
another line

Mikael Magnusson

Messages sorted by: Reverse Date, Date, Thread, Author