sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)
Sophie ([personal profile] sophie) wrote in [community profile] command_liners2010-11-03 01:32 pm
Entry tags:

xargs and apostrophes/spaces

If you've ever tried using xargs with a list of filenames, you've probably at some point come across errors like these:

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

ls: cannot access /home/sophie/directory: No such file or directory
ls: cannot access with: No such file or directory
ls: cannot access spaces: No such file or directory
ls: cannot access in/blah.txt: No such file or directory


Both of these errors are due to xargs by default interpreting some characters as special; in the first one, it won't allow apostrophes, and in the second it treats spaces as if they meant separate arguments. And the -0 switch doesn't help at all if you're using newlines.

Both of these errors can be resolved very easily: just add the -d"\n" switch before the command you want xargs to execute. This tells xargs that you don't want xargs to mess with your input at all except to treat newline characters as delimiters. This time, you should find that both apostrophes and spaces are accepted properly.
karmag: Stylized face based on Dreamwidth logo (Default)

[personal profile] karmag 2010-11-03 06:42 pm (UTC)(link)
Yeah, it doesn't work here.

(Anyone here know a lot about POSIX and portability? If no one else does, perhaps I should read up on it and try to post something.)
pauamma: Cartooney crab wearing hot pink and acid green facemask holding drink with straw (Default)

[personal profile] pauamma 2010-11-03 07:02 pm (UTC)(link)
I have the SUSv3 docs as dead electrons, but I never read them.