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

Re: Bash globbing files only?

Daniel Qarras wrote:

Yep, that would work, but I guess my question was a bit poorly
formulated. I am writing a bash script that has:


and I'd like to have "files=..." without using find or other
commands if at all possible.


Of course the best way is with the find command, being

find / -type f

Any reason why you'd rather use ls instead of find?

I want just the files from the current directory, not from any subdir.
And I'd prefer some bash globbing if possible for performance/elegancy
reasons :)

Find has more options than you want to know about:

find . -maxdepth 1 -type f -name 'pattern'

Don't forget to quote 'pattern' so the shell won't expand it.

Or you could do something like:

ls -ld pattern |sed -e '/^d/d' -e 's/.* //'
(remove the lines starting with d and all the stuff before the name).

The only way to do it without an external command would be to expand the list in the shell and cycle though the list eliminating the directories with a [ -d $VAR ] test. See 'man test' for the options, but it really is a shell built-in.

  Les Mikesell
  lesmikesell gmail com

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