Secondary menu

find anoyances: the ‘ error

find anoyances: the ‘ error

Written by on

I was working on a client site today, and I needed to find a SQL statement in one of the files, so I went to search the docroot. I started like this:

[root@clientsite html]# find . -type f | awk “{print $1}” | xargs grep -i ‘SELECT COUNT(DISTINCT(n.nid))’
xargs: unmatched single quote

Well, huh, I remember seeing that before, but not why or where or when. What’s going on?

Ok, let’s try a simpler version:

[root@h2otown html]# find . -type f | xargs grep -i ‘SELECT COUNT(DISTINCT(n.nid))’
xargs: unmatched single quote

Nope. Hmm. Ok, how about:

[root@h2otown html]# find . -type f | awk “{print $1}” | xargs grep -i ‘SELECT COUNT(DISTINCT(n.nid))’
xargs: unmatched single quote

Nope! Hey, what’s going on here? Turns out there has been an open bug in xargs for literally years:
http://savannah.gnu.org/bugs/?func=detailitem&item_id=10678

Feiyun has a workaround with Sed, but it looks a little expensive:

Date: Sunday 20/08/06 at 08:09 By: Feiyun Wang
I use “sed” and “tr” to walk around this bug:
find -mindepth 2 -type f | sort -S 4M > $$newmd5.file
sed -e “s/^\(.*\)$/\”\1\”/” $$newmd5.file | tr -s \r\n \0 | xargs -0 -r
md5sum >> $$md5sum

But, that’s complex. Later in the same archive it’s addressed by the mantainers:

——————————————————-
Date: Friday 22/10/04 at 17:18 By: James Youngman
If you want to avoid quote processing, use the -0 option. I have updated
the error message in CVS to point this out.

——————————————————-
Date: Friday 15/10/04 at 17:41 By: Bob Proulx
The -0, –null option was designed for just these cases. Unfortunately ls is
not the best tool to produce null terminated strings. But ‘find’ is good
here.

Your ‘ls -1′ command is roughly equivalent to ‘find . -maxdepth 1′. Use
find’s -print0 option and xarg’s -0 option to protect against unusual file
names.

find . -maxdepth 1 -print0 | xargs -r0

The question I have is why the bug hasn’t been closed. By the way, the -0 flag works.

No Responses Yet
Add a Response