bugfindutils - Bugs: bug #10678, xargs: unmatched single quote

 
 

bug #10678: xargs: unmatched single quote

Submitted by:  Zurd <zurd>
Submitted on:  Fri 15 Oct 2004 01:29:25 AM UTC  
 
Category:  xargs Severity:  2 - Minor
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  None Fixed Release:  None

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Mon 21 Aug 2006 01:22:35 PM UTC, comment #9: 

Upgraded to GNU xargs version 4.2.20, the command:
find -type f -print0 | xargs -0 -r md5sum
works for Windows/GnuWin32 too.
Thanks!

Feiyun Wang <feiyunw>
Sun 20 Aug 2006 10:48:46 AM UTC, comment #8: 

Command 4 works fine for me.  Your command 5 is slightly wrong.  By default xargs does nothing with {} unless you specify -I.  Example:

james@orbital:~$ mkdir C#
james@orbital:~$ cd C#
james@orbital:~/C#$ touch "C# programmer's guide.doc"
james@orbital:~/C#$ ls -1
C# programmer's guide.doc
james@orbital:~/C#$ find -type f -print0 | xargs -0 -r md5sum
d41d8cd98f00b204e9800998ecf8427e  ./C# programmer's guide.doc
james@orbital:~/C#$ find -type f -print0 | xargs -0 -I{} -r md5sum {}
d41d8cd98f00b204e9800998ecf8427e  ./C# programmer's guide.doc

You used quotes in your fifth command, but in fact xargs does not pass the commands it executes to the shell (nor does find -exec).  It just executes them directly.  Therefore no quoting of the filenames to protect them from interpretation by the shell is needed.

James Youngman <jay>
Project Administrator
Sun 20 Aug 2006 10:35:49 AM UTC, comment #7: 

Thanks James a lot! I found "sort -z" very useful.

My problem is that I need the intermediate $$newmd5.file, and the space in the original filenames makes double quote(") inevitable to me, for example:
1) mkdir C#
2) cd C#
3) touch "C# programmer's guide.doc"
4) find -type f -print0 | xargs -0 -r md5sum
5) find -type f -print0 | xargs -0 -r md5sum \"{}\"
Command 4) and 5) output the same error message:
md5sum: {}: No such file or directory
md5sum: ./C#: No such file or directory
md5sum: programmer's: No such file or directory
md5sum: guide.doc: No such file or directory

I am using Windows XP/GnuWin32 and
GNU xargs version 4.1

As the $$newmd5.file is used elsewhere and there are too many files there, I wish not walk through the directory twice (with -print and -print0 respectively).
I suggest options like "grep -F -f FILE", if new options were acceptable.

Feiyun Wang <feiyunw>
Sun 20 Aug 2006 09:07:09 AM UTC, comment #6: 

You should also be able to do it this way:

find -mindepth 2 -type f -print0 | sort -z -S 4M | xargs -0 -r md5sum >> $$md5sum

or this way

find -mindepth 2 -type f -exec md5sum {} \+ | sort -k2 >> $$md5sum

James Youngman <jay>
Project Administrator
Sun 20 Aug 2006 08:09:37 AM UTC, comment #5: 

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

Feiyun Wang <feiyunw>
Tue 19 Apr 2005 11:24:49 AM UTC, comment #4: 

Thanks James for the warning message in xargs about the unmatched single quote, it's much better now :-)

Helps to debug a command when you have an unmatched single quote and you want to make it work.

Sorry for the 6 months delay reply, savannah didn't include me by default in the Carbon Copy list :(

Zurd <zurd>
Fri 22 Oct 2004 05:18:49 PM UTC, comment #3: 

If you want to avoid quote processing, use the -0 option.   I have updated the error message in CVS to point this out.

James Youngman <jay>
Project Administrator
Fri 15 Oct 2004 05:41:28 PM UTC, comment #2: 

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

Does this address your issue?

Bob Proulx <rwp>
Project Member
Fri 15 Oct 2004 10:06:20 AM UTC, comment #1: 

Unfortunately this is the way that xargs(1) is supposed to behave.   I agree it's undesirable in many ways, but GNU Findutils' xargs is supposed to be compatible with other implementations of xargs, which means making it work in this way.

This bug report will be treated as an enhancement request to provide a way of solving this problem.  Perhaps an option to turn off quote processing and EOF marker processing.

James Youngman <jay>
Project Administrator
Fri 15 Oct 2004 01:29:25 AM UTC, original submission:  

From package 4.1.20-r1

Description:
xargs doesn't offer an option to bypass a quote (') when there is one in the filename or directory.

How-to reproduce :
1) mkdir "test'"
2) ls -1 | xargs -x -i "{}" new_test

Actual results:
xargs: unmatched single quote

What it should do:
Change the directory called test' to new_test

Zurd <zurd>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

 

 

Follow 7 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-08-20 jay Carbon-Copy- => Added feiyunw
2005-04-19 zurd Carbon-Copy- => Added zurd3@yahoo.com
2004-10-22 jay StatusNone => Invalid
    Open/ClosedOpen => Closed
    Summaryxargs: unmatched single quote (enhancement request) => xargs: unmatched single quote
2004-10-15 jay Severity3 - Normal => 2 - Minor
    Summaryxargs: unmatched single quote => xargs: unmatched single quote (enhancement request)

Back to the top


Powered by Savane 3.5