On 01/13/2011 04:53 PM, Pádraig Brady wrote: > > It would be nice not to mandate it, but without it > a script containing the following for example could hang: > > path=$(basename $path 2>/dev/null || echo default_path) > > Perhaps we should only support --files0-from > and the normal filtering case can be handled with: > > find / | xargs basename -a > > In fact thinking more about it we might not need --files0-from either. > It's used in du,wc, and sort as they need to deal with all files > from a single process invocation (to generate totals etc.) > But that's not the case for basename.
The moment you output more than one file name, you need the ability to choose to use NUL termination to avoid output ambiguity. wc needs --files0-from because wc tracks totals over multiple files, but 'xargs -0 wc' might split the invocation resulting in multiple total lines instead of the desired single total line. sort needs --files0-from for the same reason - if broken into multiple processes, the set of files is not sorted into a single result. sort also has -z/--zero-terminated, to operate on NUL-terminated rather than newline-terminated input/output lines. basename does not change its output (no multiple total lines, and no missed interpolation of input), so I agree that basename --files0-from does not make sense, after all. xargs -0 basename is sufficient for the input side of things. However, there's still the issue of the output side of things. basename $'a\nb' results in two lines, even though it was only over one file. When basename only accepted one argument, there was no ambiguity. But even doing 'xargs -0 -n 1 basename' is ambiguous, and since $() eats all trailing newlines rather than just one, it becomes difficult to use shell constructs to get exactly one trailing byte stripped. So that argues that we need -z/--zero-terminated. basename -z a => $'a\0' (rather than the current $'a\n') basename -z -a a b => $'a\0b\0' > So in summary, just implement -a and -s like BSD does? I think you've persuaded me that a filter mode doesn't buy us much (it's only useful if unambiguous, but xargs -0 works just as well at giving us unambiguous input), but we do need -z in addition to BSD's -a and -s. -- Eric Blake ebl...@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature