Re:Things you (probably) didn't know about xargs
by premchai21 on Sunday June 26, 2011 @05:54PM
(#2699211)
Would not « print0() { tr '\n' '\0'; } » work in most cases? Does your utility do something special to existing instances of \0? That's the only case I can imagine where the transformation is necessarily lossy and it's not clear what to do. I suppose in theory you could have newline normalization or something too.
Re:Things you (probably) didn't know about xargs
by barrkel on Sunday June 26, 2011 @06:45PM
(#2699347)
No, because that doesn't handle command-line arguments or '-' in the same way that cat does. It also doesn't handle the differences between DOS, Unix and Mac (\r, \n and \r\n) line endings properly. Finally, it's also slower than my 80-line C version.
Re:Things you (probably) didn't know about xargs
by billpg on Monday June 27, 2011 @04:36AM
(#2700607)
If filenames can contain LF characters, 'find | grep foo' is also wrong.
(Interesting idea with print0, but I fear this is mere symptomatic relief, rather than actually fixing the problem.)
Re:Things you (probably) didn't know about xargs
by barrkel on Monday June 27, 2011 @10:28PM
(#2703791)
As I already said, newlines[1] are vanishingly rare in filenames (most file manager UIs treat attempts at introducing a newline into the name as as committing the file rename), so I find it useful, so I wrote the utility, which only I use.
How you figure my solution to my problem is only symptomatic treatment, with technical drawbacks I already mentioned but treat as acceptable, is beyond me.
[1] As I mention in a cousin comment to this one, my utility handles all usual ASCII forms of newlines - \r, \n and \r\n (and \n\r for good measure).
I wrote a utility I named print0, which simply converts line-oriented input into null-terminated output. Very useful for building pipelines of line-oriented utilities, where each line is a filename. It's quite common to have spaces in filenames (if nothing else, user files on NAS shares), and vanishingly rare to see newlines, so I find it to be a sensible tradeoff. Things like 'find | egrep | sed | print0 | xargs -0' work as you'd expect.