Bash globbing files only?
Cameron Simpson
cs at zip.com.au
Wed Jan 31 00:42:24 UTC 2007
On 30Jan2007 15:24, Jacques B. <jjrboucher at gmail.com> 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 at zip.com.au> 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
More information about the fedora-list
mailing list