![]() |
Quote:
Quote:
at all... plus, there is still a discernible difference when used in this example. Back to the Foo directory: Code:
$ ls -1t |
xargs
Sorry to beat this horse again... but when I actually type it out,
I sometimes start to understand it better. Guess this won't be any big news, but -- while the magical xargs -I% works wonders on paths with spaces -- it still stumbles on single quotes: Code:
$ cd Foo; ls -1 Employing hayne's handy enquoter makes all go well: Code:
$ ls -1 | sed 's/^.*$/"&"/' | xargs -I% file % Code:
$ ls -1"Bartlett's Quotations" into ""Bartlett's Quotations"" which -in effect- becomes Bartlett's Quotations Let's tweak enquoter so it won't quote any double quotes: Code:
$ ls -1 | sed '/"/!s/^.*$/"&"/'Code:
$ ls -1 | sed '/"/!s/^.*$/"&"/' | xargs -I% file % Code:
$ ls -1 | sed '/"/!s/^.*$/"&"/' | xargs -I% file "%"Code:
$ ls -1 | sed '/"/!s/^.*$/"&"/' | xargs -I% file \"%\" (Umm, not really). FORGET IT. It's hopeless that way. Must resort to null chars to manage *all* possible cominations of quotes... Code:
$ find . -name "*i*" -print0 | xargs -0 -I% file %Add the -n1 option to pass them one at a time. Code:
$ find . -name "*i*" -print0 | xargs -0 -n1 -I% file %-- But: must we always use find's print0 to talk to xargs -0 ? The original ls -1t | head -2 had a particular purpose. Isn't there some way we can insert nulls after any command's list output? Let's try tr Code:
$ ls -1 | tr "\n" "\000\n" | xargs -0 -n1 fileGoing for broke... Code:
$ ls -1t | head -2 | tr "\n" "\000\n" | xargs -0 -n1 -I% cp -v % %.bak-HI- |
Using 'tr' to change newlines into null characters is a good idea.
But do you still need the newlines if you do that? I.e. wouldn't tr "\n" "\000" work just as well? |
Thanks hayne... guess I got so "caught-up-in-the-moment" that
I wasn't thinking about further code reduction. I wonder though if that newline might be missed... further down the pipeline. (?) [No, I guess you're right.] Well, we're even then: You trimmed nuller() { /usr/bin/tr "\n" "\000"; } ...and I tweaked enquoter() { /usr/bin/sed '/"/!s/^.*$/"&"/'; } ;) (Not of much use I guess, unless the entire "name" was quoted.) |
| All times are GMT -5. The time now is 05:28 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.