Re: Bash globbing files only?

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

 



On 30Jan2007 15:24, Jacques B. <jjrboucher@xxxxxxxxx> 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.

No. For _one_ run the cost is small. If something calls this code many
times, find is MANY MANY times more costly that an in-shell forkless
piece of code.

| 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.

This depends what you want. But yes. But you can do this:

  for f in .* *
  do
    case "$f" in . | .. ) continue ;; esac

which gets it all.
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

The word is not the thing.
The map is not the territory.
The symbol is not the thing symbolized.  - S.I. Hayakawa

[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