Aéris wrote:
> Le 17/09/2011 00:40, Bob Proulx a écrit :
> > Ah... Very good! An excellent suggestion! 'find' rocks! I will
> > note three things here however.
> >
> > * One is that the find will recurse down through a possibly deep
> > hierarchy of directories. It isn't an identical alternative for just
> > looking for *.txt in the current directory. But probably that
> > difference isn't important here. Or perhaps that difference will be a
> > really desirable feature.
>
> Use « -maxdepth 0 » to limit to the current level only
Yes. One of the many non-standard options available.
> > * Secondly if the add-pre-nl.sh script handle multiple file arguments
> > then instead of \; use + so that it calls it fewer times with as many
> > file arguments as possible. It will be more efficient that way.
>
> In this case, I prefere using « xargs » :
> find -type f -name "*.txt" | xargs add-pre-nl.sh
> And if there is space/single-quote/double-quote/new-line in some filenames :
> find -type f -name "*.txt" -print0 | xargs -0 add-pre-nl.sh
Using find's builtin and POSIX standard "{} +" is preferred over the
GNU extension and non-standard "-print0 | xargs -0". Standard is
better than better. And in this case it really is better and has the
fortune of being standard as well. :-)
> > * And lastly that you forgot to include the directory path to find,
> > probably a '.' wanted here.
>
> No, « find » considers the current directory if no path is given =)
I had missed that GNU extension. But that isn't standard either.
Better to learn portable scripting first and then use the extensions
as needed knowing that they are not portable. :-)
Bob
Attachment:
signature.asc
Description: Digital signature