Re: Bash globbing files only?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 30 Jan 2007, Jacques B. wrote:

>   files=
>   for f in *
>   do [ -f "$f" ] && files="$files $f"
>   done
>   ... do stuff with $files ...
>
> If you've got to deal with filenames with whitespace in them you need
> to be trickier.

I like how this works.  But you are right, it does cause a problem for
filenames with spaces.  As far as cpu time (preceding the command with
"time" to get same), we are only talking a few 1/100th of a second
difference with the find command.  The find command is more robust as
it will properly deal with filenames with spaces.  Not to mention find
will also yield hidden files (i.e. .file) whereas the above won't.
All depends on your needs as to which will serve you better.


Note, that find also solves another problem: namely, that if the globbing generates a line length beyond the max for bash (in either the for or the concatenation), then the script will fail. This won't happen with find.

Steve Friedman

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux