the joy and non-joy of globbing
John Summerfied
debian at herakles.homelinux.org
Wed Dec 21 12:18:37 UTC 2005
Robert P. J. Day wrote:
> as a quick demonstration on how globbing might run into the shell
> limits, try the following few commands. first, just try:
>
> $ ls /*
>
> the output of this command is not important, all that's important is
> that the shell had to expand the wildcarding to generate the command
> to run.
>
> if that worked, push it a bit harder:
>
> $ ls /*/*
>
> if that worked, a bit harder still:
>
> $ ls /*/*/*
>
> sooner or later, you'll hit the shell's limit as to just how large a
> command it can construct.
which is why I'm for ever telling people, "Don't do that." Especially in
scripts.
This is far more robust:
find <paths> <selection criteria> <printing instructions> \
| while read name
do something with ${name}
done
or
find <paths> <selection criteria> <printing instructions>\
| xargs --no-run-if-empty <more args> something with
Sometimes this is appropriate:
find <paths> <selection criteria> -exec prog {} \;
Note: watch out for spaces in names. They're legal, but cause havoc for
the unwary.
Homework:
Read the man pages for
find
bash <:-)>
xargs
--
Cheers
John
-- spambait
1aaaaaaa at computerdatasafe.com.au Z1aaaaaaa at computerdatasafe.com.au
Tourist pics http://portgeographe.environmentaldisasters.cds.merseine.nu/
do not reply off-list
More information about the users
mailing list