xargs: unmatched single quote
I was learning some shell commands in a little more detail when I came across this situation:
I made a file by the name of foo, by giving this command. (pwd is /home/akudewan/files/)
So, I did:
I made a subdirectory and did a "cd" to ~/files/temp/. Then I copied foo.txt here and also made another file "file.txt" I changed the command to:
My best guess is that the output of find contains a single quote.
One remedy for this could be:
$ find -type f | grep -ve "'" | xargs ...
perhaps you could post the output of these commands:
$ find --version
$ grep --version
$ xargs --version
PS. "pwd is /home/akudewan/files/" is _slightly_ incorret: pwd is an abbreviation for 'print [current] working directory', whereas cwd is 'current working directory' (or something to that effect). Thus, it would have been more correct to say "cwd is /home/akudewan/files". I hope you don't think of this as criticism, I'm just trying to enlighten you ;)
Thanks jonaskoelker. There was a file that had a single quote (bruce lee's jeet kune do.pdf) ;)
I renamed that file and the command worked perfectly. But how do I go about it if there is a quote?
fixing the quotes:
$ find -type f | sed -e "s/'/\\'/g" | xargs grep -e 'some regex...'
the sed call translates all "'" into "\'" (quote to backslash quote).
In case you have files containing other funny characters (# and " in particular), you may want to escape those as well.
have a look at either 'man sed' or 'info sed'.
Also, you might want to upgrade grep, find and xargs (I run 2.5.1 and 4.1.20 x 2, respectively).
hope this helps,
Thanks for all the help jonaskoelker. I'll look into this more on google and on the man pages. I've got the overall gist.
In case anybody else is still finding this thread when searching for the same issue (like me):
find also has a -print0 option that separates output arguments with the null character, and xargs has a -0 flag to interpred arguments as delimited by the null character, which then also avoids interpreting backslashes and quotes as special. So:
find -type f -print0 | xargs -0 grep -e 'some regex...'
|All times are GMT -5. The time now is 08:18 PM.|