Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Why does xargs strip quotes from input text?

Here is a simplified example:

echo "/Place/='http://www.google.com'" | xargs echo

outputs

/Place/=http://www.google.com

Is there any way to work-around this? (xargs -0 doesn't help me)

share|improve this question
1  
xargs treats quotes and backslashes specially as part of the spec. Post what you are trying to do with xargs instead. –  jw013 May 8 '12 at 13:31
    
xargs -0 works for me here... Why doesn't it help you? –  derobert Apr 8 '13 at 16:24

2 Answers 2

up vote 3 down vote accepted

From the xargs manual:

If you want an input argument to contain blanks or horizontal tabs, enclose it in double quotes or apostrophes. If the argument contains a double quote character ("), you must enclose the argument in apostrophes. Conversely, if the argument contains an apostrophe ('), you must enclose the argument in double quotes. You can also put a backslash (\) in front of a character to tell xargs to ignore any special meaning the character may have (for example, white space characters, or quotes).

This means you can escape quotes if the quotes are quoted themselves:

$ echo "/Place/=\'http://www.google.com\'" | xargs echo
/Place/='http://www.google.com'

will work but echo /Place/=\'http://www.google.com\' | xargs echo will not.

share|improve this answer

You could use GNU Parallel instead:

$ echo "/Place/='http://www.google.com'" | parallel echo
/Place/='http://www.google.com'

Then you do not have to do the quoting yourself.

Learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.