sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)
[personal profile] sophie posting in [community profile] command_liners
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.

Date: 2010-11-03 06:42 pm (UTC)
karmag: Stylized face based on Dreamwidth logo (Default)
From: [personal profile] karmag
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.)

Date: 2010-11-03 07:02 pm (UTC)
pauamma: Cartooney crab wearing hot pink and acid green facemask holding drink with straw (Default)
From: [personal profile] pauamma
I have the SUSv3 docs as dead electrons, but I never read them.

Profile

command_liners: A command line prompt with a blinking cursor after it, green against black. (Default)
Command Liners

January 2022

S M T W T F S
      1
2 345678
9101112131415
16171819202122
23242526272829
3031     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 13th, 2025 09:50 pm
Powered by Dreamwidth Studios