Sample Header Ad - 728x90

Properly escaping output from pipe in xargs

11 votes
5 answers
20627 views
Example: % touch -- safe-name -name-with-dash-prefix "name with space" \ 'name-with-double-quote"' "name-with-single-quote'" \ 'name-with-backslash\' xargs can't seem to handle double quotes: % ls | xargs ls -l xargs: unmatched double quote; by default quotes are special to xargs unless you use the -0 option ls: invalid option -- 'e' Try 'ls --help' for more information. If we use the -0 option, it has trouble with name that has dash prefix: % ls -- * | xargs -0 -- ls -l -- ls: invalid option -- 'e' Try 'ls --help' for more information. This is before using other potentially problematic characters like newline, control character, etc.
Asked by Gerry Lufwansa (523 rep)
Aug 11, 2017, 12:17 PM
Last activity: Dec 6, 2024, 11:00 AM