[svlug] xargs and filenames with shell special characters?
steffl at bigfoot.com
Thu Oct 4 04:34:01 PDT 2001
"Karsten M. Self" wrote:
> on Sun, Sep 23, 2001 at 01:55:25PM -0700, Erik Steffl (steffl at bigfoot.com) wrote:
> > is there any way to make xargs (and other programs) work with files
> > that have shell special characters in the filename?
> > e.g. there's a file single'quote, how to make following command work:
> > find ~ -name single\* -print |xargs ls
> > what I get is:
> > xargs: unmatched single quote
> > I know I can put backslash before special character to un-special them
> > but that's not possible when list of the filenames is generated by
> > program (e.g. find). Is there any solution to this problem? [apart from
> > writing (sed/awk/perl etc.) script that would escape all the special
> > characters]
> There's the '-print0' and '-0' (that's zero/nil, not letter oh) 'find'
> and 'xargs' arguments, which gets you past some issues.
> I tend to migrate to 'for file in $( expression )' processing in this
> case, though:
> for file in $( find ~ -name single\* -print )
> xargs ls "$file"
> ...which seems to work as desired.
thanks, both work (second one without xargs, if anybody's trying it),
one question remains:
bash-2.05$ ls rrr*
rrr rrr"rrr rrr'rrr
bash-2.05$ ls rrr*|xargs
xargs: unmatched double quote
why does xargs care about single quote? and why it suddenly does not
care when one uses -0? I mean -0 is useful with find's -print0 but does
not help in other cases (one has to use for loop approach in those cases
which xargs was designed to replace).
based on man page the xargs should simply read stdin, line by line,
and supply it to the command (or echo, if no command is given). this
unmatched quote stuff looks more like a bug then a feature...
More information about the svlug