Bash globbing files only?

Les Mikesell lesmikesell at gmail.com
Mon Jan 29 07:04:04 UTC 2007


Daniel Qarras wrote:
> Hi!
> 
>>> Yep, that would work, but I guess my question was a bit poorly
>>> formulated. I am writing a bash script that has:
>>>
>>> dirs=[^.]*/
>>>
>>> and I'd like to have "files=..." without using find or other
>> external
>>> commands if at all possible.
>>>
>>> Thanks.
>>>
>> 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 at gmail.com




More information about the users mailing list