[svlug] xargs and filenames with shell special characters?
bill at billjonas.com
Thu Oct 4 15:18:01 PDT 2001
On Thu, Oct 04, 2001 at 11:22:35AM -0700, Karsten M. Self wrote:
> ...but it doesn't work without the '-print0/-0' trick. I'm not sure if
> this is a shell issue or an xargs issue, I suspsect the latter. Any
> gurus know what's going on?
I don't consider myself a guru, but I believe that xargs simply invokes
a shell for each batch of arguments. It's kind of like doing '<command>
$(<othercommand>)', but xargs guarantees that you won't exceed
command-line length limits, and fires up the command as many times as is
necessary to handle all the input. I imagine that xargs fires up
something like 'sh -c <command> <output from othercommand>', which is
why you get weird behavior with spaces and other special characters. I
further imagine that the -0 option for xargs does something like
'IFS=<ASCII null> sh -c <command> <output from othercommand>'. Dunno
for sure, but this seems consistent with the behavior I'm seen.
Bill Jonas * bill at billjonas.com * http://www.billjonas.com/
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." -- Benjamin Franklin
More information about the svlug