On 01/12/2011 11:43 AM, Jeff Blaine wrote:
I was surprised to find this today.
The following fails:
echo /some/place/foo.txt | basename
This also fails:
find /somewhere -print | xargs basename
This *does* work though, somehow, when the above does not:
echo /some/place/foo.txt | xargs basename
What is going on here? dirname is the same way.
POSIX requires that basename and dirname be passed arguments; they are
not required to run as filters.
That said, it would be awesome if someone would contribute the patches
to emulate the BSD extensions of:
basename [-a] [-s suffix] string [...]
From there, it's not much harder to implement extensions that 0
arguments is an extension to operate in filter mode (although we may
want to require the use of basename --filter to make it obvious, and we
would certainly want basename --files-from0 to operate on find -print0
output).
But someone has to contribute the patch - are you willing?